我現(xiàn)在通過spring-boot + spring-mongo 做一個小demo ,都是最新版本 , 現(xiàn)在出現(xiàn)了一個問題就是無論如何都不能連接到其他的庫 ,只能連接到mongodb默認(rèn)的test庫 , 是什么原因 ?
配置 application.yml:
spring.data.mongodb.uri: mongodb://localhost:27017/mongo
按理說這里應(yīng)該連接到mongo庫才對 。我的mongodb沒有配置權(quán)限驗證,及不需要密碼和用戶名
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);
}
然后訪問拿到的內(nèi)容是test庫里面的 , 到底怎么回事 ?
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