0

i'm new with spring.

I'm using maven to build my webapp. I have the following structs:

  1. pom.xml
  2. src/main/[java/resources]

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!

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.