Spring的自動注入是無法注入到靜態類的
並且一個對象如果手動new的話,這個對象里面的自動注入也是不起作用的
所以如果需要讀取配置文件到靜態的工具類中
就要使用 @Configuration 和 @Bean注解來調用set方法讀取
代碼如下:
@Configuration
public class SearchAroundConfigration_jdbc {
@Autowired
private Environment env;
@Bean
public int readConf() {
SearchAroundUtil_jdbc.setUsername(env.getProperty("spring.data.neo4j.username"));
SearchAroundUtil_jdbc.setPassword(env.getProperty("spring.data.neo4j.password"));
SearchAroundUtil_jdbc.setUri(env.getProperty("spring.data.neo4j.uri").replaceAll("http:", "jdbc:neo4j:"));
return 1;
}
}
