【发布时间】:2014-11-27 10:02:07
【问题描述】:
我想在 SomeIfaceDaoImpl 中使用 'someotherproperty' 值
但是当我调试时,它总是空的,在我的 bean 定义和我的 bean 构造函数中也是如此。我也尝试在我的类中使用 @Value 注释,但这也不起作用。
但是,所有数据库值都可以正常工作,并且可以在 jdbcTemplate bean 中使用。
我的属性文件包含
database.url=jdbc:mysql://localhost:3306/databasename
database.username=root
database.password=password
someotherproperty=HelloWorld
我的配置类:
@Configuration
@Profile("production")
@ComponentScan(basePackages = { "com.packagename" })
@PropertySource({"classpath:packagename.properties"})
public class ContextConfig {
@Value("${database.url}")
private String url;
@Value("${database.username}")
private String username;
@Value("${database.password}")
private String password;
@Value("${someotherproperty}")
private String someotherproperty;
@Bean(name = "jdbcTemplate")
public JdbcTemplate jdbcTemplate() {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(StringUtil.appendObjects(url, "?", "useServerPrepStmts=false&rewriteBatchedStatements=true"));
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUsername(username);
dataSource.setPassword(password);
jdbcTemplate.setDataSource(dataSource);
return jdbcTemplate;
}
@Bean
public ISomeIfaceDao iSomeIfaceDao() {
return new ISomeIfaceDaoImpl(); //<---- I would like to have someotherproperty value here or inside the constructor
}
}
谢谢。
【问题讨论】:
标签: java spring annotations