Spring Boot和MongoDB配置 [英] Spring Boot and MongoDB configuration
本文介绍了Spring Boot和MongoDB配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是春天的新人.
我正在使用maven构建我的 web应用. 我有以下结构:
I'm using maven to build my webapp. I have the following structs:
- pom.xml
- src/main/[java/resources]
没有* .xml文件,*.conf或* .properties ...什么都没有.
there is no *.xml file, *.conf or *.properties... nothing.
Application.java
Application.java
@Autowired
private UserRepository repository;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
repository.deleteAll();
repository.save(new User("test", "123"));
List<User> users = repository.findByLogin("test");
...
}
User.java和UserRepository.java
Also, User.java and UserRepository.java
public interface UserRepository extends MongoRepository<User, String> {
public List<User> findByLogin(String login);
}
它有效!!!
我的问题是:如何更改mongo的配置?数据库,密码?
my question is: How I change the configuration of mongo? database, password??
谢谢!
推荐答案
创建文件:src \ main \ resources \ application.properties
Create the file: src\main\resources\application.properties
并在此文件中输入:
# MONGODB (MongoProperties)
spring.data.mongodb.host= # the db host
spring.data.mongodb.port=27017 # the connection port (defaults to 27107)
spring.data.mongodb.uri=mongodb://localhost/test # connection URL
spring.data.mongodb.database=
spring.data.mongodb.authentication-database=
spring.data.mongodb.grid-fs-database=
spring.data.mongodb.username=
spring.data.mongodb.password=
spring.data.mongodb.repositories.enabled=true # if spring data repository support is enabled
这篇关于Spring Boot和MongoDB配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文