前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >springboot2.0 常见问题找不到

springboot2.0 常见问题找不到

作者头像
用户5899361
发布2020-12-07 14:18:24
7320
发布2020-12-07 14:18:24
举报
文章被收录于专栏:学习java的小白

报错信息如下

代码语言:javascript
复制
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.1.RELEASE)

2019-05-17 11:59:15.026  INFO 7792 --- [           main] com.bdqn.Start                           : Starting Start on PC-20180826RQMV with PID 7792 (E:\IDEA\springboot1\target\classes started by Administrator in E:\IDEA\springboot1)
2019-05-17 11:59:15.031  INFO 7792 --- [           main] com.bdqn.Start                           : The following profiles are active: dev
2019-05-17 11:59:15.115  INFO 7792 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4f6ee6e4: startup date [Fri May 17 11:59:15 CST 2019]; root of context hierarchy
2019-05-17 11:59:16.638  INFO 7792 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
2019-05-17 11:59:16.663  INFO 7792 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-17 11:59:16.663  INFO 7792 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2019-05-17 11:59:16.667  INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : Loaded APR based Apache Tomcat Native library [1.2.18] using APR version [1.6.5].
2019-05-17 11:59:16.668  INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2019-05-17 11:59:16.668  INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2019-05-17 11:59:16.671  INFO 7792 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.1  11 Sep 2018]
2019-05-17 11:59:16.864  INFO 7792 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2019-05-17 11:59:16.867  INFO 7792 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-05-17 11:59:16.868  INFO 7792 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1759 ms
2019-05-17 11:59:16.998  INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2019-05-17 11:59:17.002  INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-05-17 11:59:17.002  INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-05-17 11:59:17.002  INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-05-17 11:59:17.002  INFO 7792 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-05-17 11:59:17.041  WARN 7792 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'testService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testServices': Unsatisfied dependency expressed through field 'testDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.bdqn.dao.TestDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2019-05-17 11:59:17.044  INFO 7792 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-05-17 11:59:17.052  WARN 7792 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2019-05-17 11:59:17.061  INFO 7792 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-05-17 11:59:17.194 ERROR 7792 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field testDao in com.bdqn.service.TestServices required a bean of type 'com.bdqn.dao.TestDao' that could not be found.


Action:

Consider defining a bean of type 'com.bdqn.dao.TestDao' in your configuration.


Process finished with exit code 1

这种报错情况有两种:

第一种:启动类注解上有@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

解决办法 去掉(exclude = DataSourceAutoConfiguration.class)

第二种:dao的接口使用注解 @Repository

解决办法:将 @Repository修改为@Mapper

情况一:

启动类:

代码语言:javascript
复制
package com.bdqn;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;



@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class Start {
    public static void main(String[] args) {
        SpringApplication.run(Start.class,args);
    }
}

Dao层

代码语言:javascript
复制
package com.bdqn.dao;

import com.bdqn.pojo.Test;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;


import java.util.List;

@Mapper
public interface TestDao {

    @Select("select * from user")
    List<Test> getAll();
}

解决办法:将启动类后面的(exclude = DataSourceAutoConfiguration.class)去掉

代码语言:javascript
复制
package com.bdqn;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;



@SpringBootApplication
public class Start {
    public static void main(String[] args) {
        SpringApplication.run(Start.class,args);
    }
}

情况二:

启动类

代码语言:javascript
复制
@SpringBootApplication
public class Start {
    public static void main(String[] args) {
        SpringApplication.run(Start.class,args);
    }

dao层

代码语言:javascript
复制
package com.bdqn.dao;

import com.bdqn.pojo.Test;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;


import java.util.List;

@Repository
public interface TestDao {

    @Select("select * from user")
    List<Test> getAll();
}

解决办法:将@Repository修改为@Mapper

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 这种报错情况有两种:
  • 情况一:
    • 启动类:
      • Dao层
      • 解决办法:将启动类后面的(exclude = DataSourceAutoConfiguration.class)去掉
      • 情况二:
        • 启动类
          • dao层
          • 解决办法:将@Repository修改为@Mapper
          相关产品与服务
          对象存储
          对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档