spring-boot - spring boot + spring data mongodb 启动报错

查看:407
本文介绍了spring-boot - 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

请问下该如何解决 ?

解决方案

缺少 spring web 依赖

这篇关于spring-boot - spring boot + spring data mongodb 启动报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆