Skip to content

Instantly share code, notes, and snippets.

@cbeams
Created April 8, 2011 12:16
Show Gist options
  • Save cbeams/909722 to your computer and use it in GitHub Desktop.
Save cbeams/909722 to your computer and use it in GitHub Desktop.
Demonstrating the problem with @feature and beans @injected from XML
@Configuration
@TxAnnotationDriven
@ImportResource("classpath:/com/company/app/db-config.xml")
public class AppConfig {
@Inject Environment env;
@Inject DataSource dataSource; // from XML -> won't work; @Feature forces autowiring before BFPP!
// ---- configure data infrastructure ----
public @Bean SessionFactory sessionFactory() { ... }
public @Bean PersistenceExceptionTranslationPostProcessor exceptionTranslationPostProcessor() { ... }
public @Bean PersistenceExceptionTranslator exceptionTranslator() { ... }
public @Bean PlatformTransactionManager txManager() { ... }
// ---- configure service and repository layers ----
// ...
// ---- configure MVC controllers and infrastructure ----
public @Bean FormattingConversionService conversionService() { ... }
public @Bean Validator validator() { ... }
public @Bean MessageCodesResolver messageCodesResolver() { ... }
@Feature
public MvcAnnotationDriven annotationDriven() {
return new MvcAnnotationDriven()
.conversionService(conversionService())
.messageCodesResolver(messageCodesResolver())
.validator(validator())
.messageConverters(new StringHttpMessageConverter())
.argumentResolvers(new TestWebArgumentResolver());
}
}
<beans>
<bean class="org.sfwk..PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/com/company/app/db.properties"/>
</bean>
<bean id="dataSource" class="...">
<property name="driverClass" value="${db.driverClass}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment