I am now making a small demo through spring-boot+spring-mongo, which is the latest version. Now there is a problem that I cannot connect to other libraries in any way, only mongodb’s default test library. What is the reason?
Yml:
spring.data.mongodb.uri: mongodb://localhost:27017/mongo
In theory, this should be connected to the mongo library. My mongodb does not have permission authentication configured and does not require a password and user name.
gradle :
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-web")
entity :
@Document(collection="customer")
public class Customer {
@Id
private String id;
private String firstName;
private String lastName;
repository :
public interface CustomerRepository extends MongoRepository<Customer, String>,QueryDslPredicateExecutor<Customer> {
}
controller :
//http://localhost:8080/id
@RequestMapping("/{id}")
public Object getmongodbID(@PathVariable String id){
return customerRepository.getIdCustomer(id);
}
Then the contents obtained from the visit are from the test library. what’s going on?
Add configuration to your application.yml or prop file
data:mongodb: database: tara host: localhost port: 27017 username: tara password: tara authentication-database: tara repositories: enabled: true