我正在尝试访问application.properties文件中Neo4jConnectionFactory类的值。我可以访问Setup bean类中的属性。但是,我希望能够从Neo4jConnectionFactory访问它们。当我尝试这样做时,我得到了空值。这可能吗?
Applications.properties
neo4j.url = bolt://localhost:7687
neo4j.user = neo4j
neo4j.password = neo4j
SetupBeans.java
@Component
public class SetupBeans {
@Bean
public Neo4jClient neo4jClient() {
return new Neo4jConnectionFactory().build();
}
}
Neo4jConnectionFactory.java
@Configuration("neo4j")
public class Neo4jConnectionFactory {
@Value("${neo4j.url}")
private String url;
@Value("${neo4j.user}")
private String user;
@Value("${neo4j.password}")
private String password;
public Neo4jClient build() {
return new Neo4jClient(getUrl(), getUser(), getPassword());
}
}
MyApplication.java
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
1条答案
按热度按时间amrnrhlw1#
我想这会自动地在前面加上前缀
neo4j
所以
@Value
语句应该省略前缀,如下所示: