Spring messageSource only works as xml (not as Spring-Java-Config) -


i have working spring mvc project , want migrate application context configuration xml java-config. works fine except messagesource bean.


following works fine:
config class gets imported config class:

package gmm;  import org.springframework.context.annotation.configuration; import org.springframework.context.annotation.importresource;  @configuration @importresource({"classpath:applicationcontext.xml"}) public class i18nconfiguration {  } 

referenced applicationcontext.xml file:

<beans     xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:context="http://www.springframework.org/schema/context"     xsi:schemalocation="         http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-3.2.xsd         http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.2.xsd ">      <bean id="messagesource"         class="org.springframework.context.support.resourcebundlemessagesource">         <property name="basename">             <value>messages</value>         </property>     </bean>  </beans> 

following not work:
moved bean java config:

package gmm;  import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.context.support.resourcebundlemessagesource;  @configuration public class i18nconfiguration {      @bean     public resourcebundlemessagesource messagesource() {         resourcebundlemessagesource source = new resourcebundlemessagesource();         source.setbasename("messages");         return source;     } } 

when use java config, usual ???key.for.message??? stuff. debugging output doesn't tell me unusual.
don't see wrong here. there obvious error in code? please tell me if don't solution cause feel im kind of dumb right now! supposed super easy isn't it?


edit: message files in src/main/resources , named messages_en.properties.
edit2: full project source code can found here: https://github.com/katharsas/gmm/tree/perfrevamp

okay, solved this!

tldr: had java-config defining messagesource bean in file (which wasn't aware off). config did override java-config, not override xml config. xml worked, java-config didn't.

how found error:

i copied servlet startup log of both versions online text diff tool (after replacing timestamps dummy text)

working code log:

information: loading xml bean definitions class path resource [applicationcontext.xml]         19  sep 25, 2014 time org.springframework.beans.factory.support.defaultlistablebeanfactory registerbeandefinition         20  information: overriding bean definition bean 'messagesource': replacing [generic bean: class [com.technologicaloddity.capturejsp.util.techoddmessagesource]; scope=singleton; abstract=false; lazyinit=false; autowiremode=0; dependencycheck=0; autowirecandidate=true; primary=false; factorybeanname=null; factorymethodname=null; initmethodname=null; destroymethodname=null; defined in file [c:\users\jan\repositories\gmm\target\classes\com\technologicaloddity\capturejsp\util\techoddmessagesource.class ]] [generic bean: class [org.springframework.context.support.resourcebundlemessagesource]; scope=; abstract=false; lazyinit=false; autowiremode=0; dependencycheck=0; autowirecandidate=true; primary=false; factorybeanname=null; factorymethodname=null; initmethodname=null; destroymethodname=null; defined in class path resource [applicationcontext.xml]] 

not working code same line:

sep 25, 2014 time org.springframework.context.annotation.configurationclassbeandefinitionreader isoverriddenbyexistingdefinition information: skipping bean definition [beanmethod:name=messagesource,declaringclass=gmm.i18nconfiguration]: definition bean 'messagesource' exists. top-level bean definition considered override. 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -