Change @Autowired
for @Resource
(from javax.annotation) and make it public
e.g.:
@Configuration
@PropertySource("classpath:database.properties")
public class HibernateConfigurer {
@Resource
public Environment env;
@Bean
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("database.driverClassName"));
dataSource.setUrl(env.getProperty("database.url"));
dataSource.setUsername(env.getProperty("database.username"));
dataSource.setPassword(env.getProperty("database.password"));
dataSource.setValidationQuery(env.getProperty("database.validationQuery"));
return dataSource;
}
}
And you must register your configurer class in WebApplicationInitializer this way
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(ApplicationConfigurer.class); //ApplicationConfigurer imports HibernateConfigurer
It's working for me! You may want to check a test project I made.
@Resource
instead of@Autowired
. See if that helps. – SpragePropertiesUtil
? Do you have aPropertySourcesPlaceholderConfigurer
or something like that ? – PortlandPropertyUtil
... – Harv