spring boot + spring data mongodb 启动报错
0 gradle
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
}
1 . 实体类。省略 get set
public class Customer {
@Id
private String id;
private String firstName;
private String lastName;
2 . repository
public interface CustomerRepository extends MongoRepository<Customer, String> {
public Customer findByFirstName(String firstName);
public List<Customer> findByLastName(String lastName);
}
3 apption
@PropertySource("classpath:application.yml")
@EnableAsync
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
4 配置文件 application.yml
#spring.profiles.default: local
配置文件 application-local.yml
spring.data.mongodb.database: test
spring.data.mongodb.uri: mongodb://localhost:27017
启动报错 :
2016-04-25 17:46:40.683 INFO 3788 --- [ main] ys.Application : Starting Application on yangshuang with PID 3788 (D:\mongodb\build\classes\main started by yangshuang in D:\mongodb)
2016-04-25 17:46:40.685 INFO 3788 --- [ main] ys.Application : No active profile set, falling back to default profiles: default
2016-04-25 17:46:40.728 INFO 3788 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4450d156: startup date [Mon Apr 25 17:46:40 CST 2016]; root of context hierarchy
2016-04-25 17:46:41.594 INFO 3788 --- [ main] o.s.s.a.AsyncAnnotationBeanPostProcessor : No TaskExecutor bean found for async annotation processing.
2016-04-25 17:46:42.168 INFO 3788 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-04-25 17:46:42.178 INFO 3788 --- [ main] ys.Application : Started Application in 1.756 seconds (JVM running for 2.097)
2016-04-25 17:46:42.179 INFO 3788 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4450d156: startup date [Mon Apr 25 17:46:40 CST 2016]; root of context hierarchy
2016-04-25 17:46:42.182 INFO 3788 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
请问下该如何解决 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
缺少 spring web 依赖
https://github.com/pkaq/tara/tree/adminLTE-mongodb
这里有个采用mongodb的示例你可以参考下,另外注意要先启动mongodb服务
另外你依赖缺少mongodb的驱动