Announcement Announcement Module

JavaConfig forum decommissioned in favor of Core Container

As described at

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at
See more
See less
Unable to combine AnnotationDrivenTx with ExternalValue. Possible bug? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to combine AnnotationDrivenTx with ExternalValue. Possible bug?


    First off, to all you JavaConfig developers; thanks for providing this great alternative to the XML Spring configuration. Keep up the good work

    I'm out of luck trying to combine AnnotationDrivenTx with ExternalValue annotations. Consider the following JavaConfig applcation config class;

    (Oh, I'm unable to create a post with 'at' sign due to restrictions of the forum (this is my first post) so I've swapped them with '#' in the code.)

    #PropertiesValueSource(locations = {
    public class AppConfig extends ConfigurationSupport {
        #ExternalValue("datasource.username") String username;
        #ExternalValue("datasource.password") String password;
        #ExternalValue("datasource.driverClassName") String driverClassName;
        #ExternalValue("datasource.url") String url;
        #ExternalValue("hibernate.dialect") String dialect;
        #ExternalValue("") String hbm2ddlAuto;
        public DataSource dataSource() {
            DriverManagerDataSource dataSource = new DriverManagerDataSource();
            System.out.println("in dataSource(): username = " + username);
            return dataSource;
        public SessionFactory sessionFactory() {
            LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
            Properties properties = new Properties();
            properties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
            properties.put("", "create");
            properties.put("hibernate.show_sql", true);
            sessionFactoryBean.setMappingResources(new String[] {
            return getObject(sessionFactoryBean, SessionFactory.class);
        public PlatformTransactionManager transactionManager() {
            return new HibernateTransactionManager(sessionFactory());

    Loading this will cause 'in dataSource(): username = null' to be written to stdout. Trying to load the class with '#AnnotationDrivenTx' commented out, will however yield whatever value set in the file.

    Any insights?

    Thanks in advance.

  • #2
    This is a bug. I've got a placeholder issue for it at

    As a workaround, use @ExternalValue methods instead of @ExternalValue fields. This seems to work just fine.

    Thanks for the report, and be sure to add yourself as a watcher to the issue to see when it's resolved.


    • #3

      Thanks for quick response. Works like a charm.


      • #4
        Note this issue has been resolved and should be available in the latest M5 nightly build.