Results 1 to 3 of 3

Thread: JavaConfig migration to Spring 3

  1. #1
    Join Date
    Jan 2012
    Posts
    3

    Question JavaConfig migration to Spring 3

    Hi to all:
    I'm trying to migrate and old project that uses Spring 2+JavaConfig 1.0.0.m3 to Spring 3. It's an application inside a Red5 server (migrating from 0.6 to 1.0RC). After solving several issues I'm totally stucked now. I've sucessfully migrated the annotations but I think that the old behaviour is different from the actual one.

    First of all, I'm not the one that created the old version, so my comments might not be totally accurate. In the old version in my opinion every method annotated with @Bean was called and therefore the bean was created. In the migrated version the behaviour seems to be different, and no method is called. My class is annotated as @Configuration for example:

    Code:
    @Configuration
    public class InMemoryNodeRepositoryConfig
    {
    	private static final String NET_FILE_NAME = "net.xml";
    
    	public InMemoryNodeRepositoryConfig()
    	{
    		System.out.println("Constructor called");
    	}
    	
    	@Bean
    	public NodeRepository nodeRepository(final Settings systemSettings) throws Exception
    	{
    		System.out.println("Bean created");		
    		final File cfgDir = Files.getConfDir(systemSettings);
    		final String thisNodeId = systemSettings.getString(Settings.NODE_ID_KEY);
    		final File netFile = new File(cfgDir, NET_FILE_NAME); 
    		return XmlNodeRepositoryLoader.load(thisNodeId, netFile);
    	}
    
    }
    The constructor is called (it's included in an xml as a bean) but the method nodeRepository it is not. Do I need any extra annotation? Is there something that I'm not understanding?

    Thanks in advance

  2. #2
    Join Date
    Apr 2007
    Posts
    307

    Default

    Make sure you have <context:annotation-config/> declared in your XML. This enables processing of @Configuration classes.
    Chris Beams
    Spring Framework committer, VMware
    http://github.com/cbeams

  3. #3
    Join Date
    Jan 2012
    Posts
    3

    Default

    Thank you so much!!, now at least is crashing but in the object creation...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •