Reputation: 89
i'm new with spring.
I'm using maven to build my webapp. I have the following structs:
there is no *.xml file, *.conf or *.properties... nothing.
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");
...
}
Also, User.java and UserRepository.java
public interface UserRepository extends MongoRepository<User, String> {
public List<User> findByLogin(String login);
}
and it works!!!
my question is: How I change the configuration of mongo? database, password??
thanks!
Upvotes: 0
Views: 6168
Reputation: 56
Create the file: src\main\resources\application.properties
and in this file, put:
# 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
Upvotes: 4