Announcement Announcement Module
Collapse
No announcement yet.
Configuration composition Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuration composition

    I'd like to ask question regarding @Configuration composition implementation. I have base class which wires specialized bean:
    Code:
    public class SpecializedDataSource {
    	@Bean
    	public DataSource dataSource() {
    		//return specialized dataSource
    	}
    }
    There is some generic configuration which wires all beans including default dataSource:
    Code:
    @Configuration
    public class DefaultConfig {
    	@Bean
    	public DataSource dataSource() {
    		//return default dataSource
    	}
    	// other beans
    }
    Now there is specialized configuration which is defined like this:
    Code:
    @Configuration
    @Import(DefaultConfig.class)
    public class SpecializedConfig extends SpecializedDataSource {}
    All above is used in JUnit like follows:

    Code:
    @Category(UnitTest.class)
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = SpecializedConfig.class)
    public abstract class MyTest {
       @Autowired
       DataSource ds;
       //...
    }
    Now it seams for some time dataSource from SpecializedDataSource was used as I wanted but recently out of sudden (it's large project and it's hard to track what change could be the cause) dataSource from DefaultConfig is being used. Is there any specification which defines what should be the precedence? Or there is no guarantee about it?
    Last edited by Martiness1; Jun 14th, 2013, 04:36 PM.

  • #2
    In first place, why do you wanted to have 2 (or multiple) dataSource beans? Do you intended to use one for Production and one for Test env? If so, then better to use the "Profile" feature introduced in 3.1. This would help you to define dataSource for test and dataSource for production separate and you can enable one of them based on the env.

    Hope this helps.

    Comment

    Working...
    X