如何在Spring启动时将neo4j url外部化为application.properites或application.yml

时间:2015-01-21 13:33:55

标签: java spring-boot spring-data-neo4j

我想使用application.yml和profiles方法来外部化db和其他基础结构依赖项。

我目前在主应用程序中硬编码了neo4j url。

@Configuration
@EnableNeo4jRepositories("com.xxx.repository")
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
public class Application extends Neo4jConfiguration {

public Application() {
    setBasePackage("com.xxx.entity");
}

@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
    return new SpringRestGraphDatabase("http://127.0.0.1:7474/db/data");
}

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}
}

更新:

@Value("${neo4jurl}")
private String neoUrl;

@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
    return new SpringRestGraphDatabase(neoUrl);
}

的src /主/资源/ application.yml

neo4jurl: http://127.0.0.1:7474/db/data

0 个答案:

没有答案