GVKun编程网logo

spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决说明

16

在本文中,我们将给您介绍关于springboot自动注入出现Considerdefiningabeanoftype‘xxx‘inyourconfiguration问题解决说明的详细内容,此外,我们还将

在本文中,我们将给您介绍关于spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决说明的详细内容,此外,我们还将为您提供关于Cannot resolve configuration property ''xxxx''、Consider defining a bean of type ''com.*.*.feign.*FeignClient'' in your configuration.、Consider defining a bean of type ''com.lvjing.dao.DeviceStatusMapper'' in your configuration.、Consider defining a bean of type ''org.springframework.data.redis.connection.RedisConnectionFa...的知识。

本文目录一览:

spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决说明

spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决说明

搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的朋友参考

Description:

Field helloService in com.example.demo.service.TestController required a bean of type ''com.example.service.HelloService'' that could not be found.


Action:

Consider defining a bean of type ''com.example.service.HelloService'' in your configuration.

然后我又看了下自己写的几个类以及注解见下面,感觉写的没有问题啊
  控制器 TestController

这里写图片描述
  接口HelloService

这里写图片描述
  接口对应的实现类HelloServiceImpl

这里写图片描述
  
  根据英文的提示是在配置中找不到一个指定自动注入类型的bean,经过多方排查得出结论:
  正常情况下加上@Component注解的类会自动被Spring扫描到生成Bean注册到spring容器中,既然他说没找到,也就是该注解被没有被spring识别,问题的核心关键就在application类的注解SpringBootApplication上
   这里写图片描述
  这个注解其实相当于下面这一堆注解的效果,其中一个注解就是@Component,在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动注册为Bean的@Service@Controller和@ Repository,至此明白问题所在,之前我将接口与对应实现类放在了与控制器所在包的同一级目录下,这样的注解自然是无法被识别的

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters={@Filter(type=CUSTOM, classes={TypeExcludeFilter.class}), @Filter(type=CUSTOM, classes={AutoConfigurationExcludeFilter.class})})
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Documented
@Inherited

 

至此,得出两种解决办法:
  1 .将接口与对应的实现类放在与application启动类的同一个目录或者他的子目录下,这样注解可以被扫描到,这是最省事的办法
  2 .在指定的application类上加上这么一行注解,手动指定application类要扫描哪些包下的注解,见下图
   这里写图片描述
  通过这两种方式,那个找不到指定Bean的错误就成功解决了。。。。。那么这篇就这样吧
  PS:控制器Controller也要放在与application同级或者子目录下,道理大致一样

Cannot resolve configuration property ''xxxx''

Cannot resolve configuration property ''xxxx''

1 问题描述

Spring Boot中的application.properties文件中,如果自定义属性会如下提示:

Cannot resolve configuration property ''xxxx''

在这里插入图片描述

2 解决方式一

这其实是一个警告,可以不用理会,正常运行,可以通过

@Value("${}")

正常获取到值,所以最暴力的方法就是关闭这个检查:

在这里插入图片描述

进入设置中的Editor-->Inspection-->Spring-->Spring Boot-->Spring Boot application properties,去掉右边勾选。

3 解决方式二(推荐)

在这里插入图片描述

这里提示Defind Configuration key a,然后按Alt+Shift+Enter后,就会创建一个addtional-spring-configuration-metadata.json的文件:

在这里插入图片描述

这里name是指定属性名字,type是类型,可以加上defaultValue指定默认值:

在这里插入图片描述

这样就不会有警告了:

在这里插入图片描述

Consider defining a bean of type ''com.*.*.feign.*FeignClient'' in your configuration.

Consider defining a bean of type ''com.*.*.feign.*FeignClient'' in your configuration.

Description:

Field *FeignClient in com.*.*.service.* required a bean of type ''***********'' that could not be found.


Action:

Consider defining a bean of type ''com.*.*.feign.*FeignClient'' in your configuration.

Disconnected from the target VM, address: ''127.0.0.1:53871'', transport: ''socket''

Process finished with exit code 1

 

添加依赖

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

 

Consider defining a bean of type ''com.lvjing.dao.DeviceStatusMapper'' in your configuration.

Consider defining a bean of type ''com.lvjing.dao.DeviceStatusMapper'' in your configuration.

"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\lib\idea_rt.jar=55273:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;C:\Users\LvjingService\Documents\EMQX_mongo_service\target\classes;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-data-mongodb\2.1.2.RELEASE\spring-boot-starter-data-mongodb-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.2.RELEASE\spring-boot-starter-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot\2.1.2.RELEASE\spring-boot-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.2.RELEASE\spring-boot-autoconfigure-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.2.RELEASE\spring-boot-starter-logging-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\LvjingService\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\LvjingService\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.1\log4j-to-slf4j-2.11.1.jar;C:\Users\LvjingService\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;C:\Users\LvjingService\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\LvjingService\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\LvjingService\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\LvjingService\.m2\repository\org\mongodb\mongodb-driver\3.8.2\mongodb-driver-3.8.2.jar;C:\Users\LvjingService\.m2\repository\org\mongodb\bson\3.8.2\bson-3.8.2.jar;C:\Users\LvjingService\.m2\repository\org\mongodb\mongodb-driver-core\3.8.2\mongodb-driver-core-3.8.2.jar;C:\Users\LvjingService\.m2\repository\org\springframework\data\spring-data-mongodb\2.1.4.RELEASE\spring-data-mongodb-2.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-tx\5.1.4.RELEASE\spring-tx-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-context\5.1.4.RELEASE\spring-context-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-beans\5.1.4.RELEASE\spring-beans-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-expression\5.1.4.RELEASE\spring-expression-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\data\spring-data-commons\2.1.4.RELEASE\spring-data-commons-2.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.2.RELEASE\spring-boot-starter-web-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.2.RELEASE\spring-boot-starter-json-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\LvjingService\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\LvjingService\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\LvjingService\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\LvjingService\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\LvjingService\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.2.RELEASE\spring-boot-starter-tomcat-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.14\tomcat-embed-core-9.0.14.jar;C:\Users\LvjingService\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.14\tomcat-embed-el-9.0.14.jar;C:\Users\LvjingService\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.14\tomcat-embed-websocket-9.0.14.jar;C:\Users\LvjingService\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;C:\Users\LvjingService\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\LvjingService\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\LvjingService\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-web\5.1.4.RELEASE\spring-web-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-webmvc\5.1.4.RELEASE\spring-webmvc-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-aop\5.1.4.RELEASE\spring-aop-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.2\mybatis-spring-boot-starter-1.3.2.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.2.RELEASE\spring-boot-starter-jdbc-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-jdbc\5.1.4.RELEASE\spring-jdbc-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.2\mybatis-spring-boot-autoconfigure-1.3.2.jar;C:\Users\LvjingService\.m2\repository\org\mybatis\mybatis\3.4.6\mybatis-3.4.6.jar;C:\Users\LvjingService\.m2\repository\org\eclipse\paho\org.eclipse.paho.client.mqttv3\1.2.0\org.eclipse.paho.client.mqttv3-1.2.0.jar;C:\Users\LvjingService\.m2\repository\com\alibaba\fastjson\1.2.7\fastjson-1.2.7.jar;C:\Users\LvjingService\.m2\repository\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-core\5.1.4.RELEASE\spring-core-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-jcl\5.1.4.RELEASE\spring-jcl-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-integration\2.1.2.RELEASE\spring-boot-starter-integration-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.1.2.RELEASE\spring-boot-starter-aop-2.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar;C:\Users\LvjingService\.m2\repository\org\springframework\integration\spring-integration-core\5.1.2.RELEASE\spring-integration-core-5.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\spring-messaging\5.1.4.RELEASE\spring-messaging-5.1.4.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\retry\spring-retry\1.2.3.RELEASE\spring-retry-1.2.3.RELEASE.jar;C:\Users\LvjingService\.m2\repository\io\projectreactor\reactor-core\3.2.5.RELEASE\reactor-core-3.2.5.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0.2.jar;C:\Users\LvjingService\.m2\repository\org\springframework\integration\spring-integration-stream\5.1.2.RELEASE\spring-integration-stream-5.1.2.RELEASE.jar;C:\Users\LvjingService\.m2\repository\org\springframework\integration\spring-integration-mqtt\5.1.2.RELEASE\spring-integration-mqtt-5.1.2.RELEASE.jar" com.lvjing.Application

. ____ _ __ _ _
/\\ / ___''_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | ''_ | ''_| | ''_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
'' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)

2019-01-15 14:46:37.017 INFO 91928 --- [ main] com.lvjing.Application : Starting Application on DESKTOP-CFAH7O4 with PID 91928 (C:\Users\LvjingService\Documents\EMQX_mongo_service\target\classes started by LvjingService in C:\Users\LvjingService\Documents\EMQX_mongo_service)
2019-01-15 14:46:37.020 INFO 91928 --- [ main] com.lvjing.Application : No active profile set, falling back to default profiles: default
2019-01-15 14:46:37.871 INFO 91928 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-01-15 14:46:37.909 INFO 91928 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 34ms. Found 0 repository interfaces.
2019-01-15 14:46:38.134 INFO 91928 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named ''errorChannel'' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2019-01-15 14:46:38.141 INFO 91928 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named ''taskScheduler'' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2019-01-15 14:46:38.146 INFO 91928 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named ''integrationHeaderChannelRegistry'' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2019-01-15 14:46:38.478 INFO 91928 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ''org.springframework.integration.config.IntegrationManagementConfiguration'' of type [org.springframework.integration.config.IntegrationManagementConfigurationEnhancerBySpringCGLIB

4944dff8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-15 14:46:38.495 INFO 91928 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ''integrationDisposableAutoCreatedBeans'' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-15 14:46:38.801 INFO 91928 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9094 (http)
2019-01-15 14:46:38.890 INFO 91928 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-01-15 14:46:38.891 INFO 91928 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-01-15 14:46:38.901 INFO 91928 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_181\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\anaconda;D:\anaconda\Scripts;D:\anaconda\Library\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\LvjingService\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Java\jdk1.8.0_181;C:\Program Files\Java\jre1.8.0_181;C:\Users\LvjingService\AppData\Local\GitHubDesktop\bin;C:\Users\LvjingService\AppData\Roaming\npm;.]
2019-01-15 14:46:39.026 INFO 91928 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-01-15 14:46:39.026 INFO 91928 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1963 ms
2019-01-15 14:46:39.757 INFO 91928 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[47.96.177.100:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout=''30000 ms'', maxWaitQueueSize=500}
2019-01-15 14:46:39.991 INFO 91928 --- [6.177.100:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:131}] to 47.96.177.100:27017
2019-01-15 14:46:40.009 WARN 91928 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''deviceStatusServiceImpl'': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ''com.lvjing.dao.DeviceStatusMapper'' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
2019-01-15 14:46:40.013 INFO 91928 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-01-15 14:46:40.021 WARN 91928 --- [ main] 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-01-15 14:46:40.026 INFO 91928 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with ''debug'' enabled.
2019-01-15 14:46:40.135 ERROR 91928 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

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

Description:

A component required a bean of type ''com.lvjing.dao.DeviceStatusMapper'' that could not be found.


Action:

Consider defining a bean of type ''com.lvjing.dao.DeviceStatusMapper'' in your configuration.

 

 

 

原错误启动文件 Application.java 

package com.lvjing;

/**
 * Created by huanghua on 2017/5/23.
 */

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;


@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class Application extends SpringBootServletInitializer {

    /**启动Spring boot服务**/
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

  

 

修改 @SpringBootApplication 注解

 

package com.lvjing;

/**
 * Created by huanghua on 2017/5/23.
 */

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;


@SpringBootApplication(exclude={DataSourceAutoConfiguration.class},scanBasePackages = {"com.lvjing.dao.*"})
public class Application extends SpringBootServletInitializer {

    /**启动Spring boot服务**/
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

  

成功!

 

2️⃣ 采用注解

@MapperScan("com.lvjing.dao")

Consider defining a bean of type ''org.springframework.data.redis.connection.RedisConnectionFa...

Consider defining a bean of type ''org.springframework.data.redis.connection.RedisConnectionFa...

Description:

Parameter 0 of method redisTemplate in com.liaojie.cloud.auth.server.config.redis.RedisConfiguration required a bean of type 
''org.springframework.data.redis.connection.RedisConnectionFactory'' that could not be found. Action: Consider defining a bean of type ''org.springframework.data.redis.connection.RedisConnectionFactory'' in your configuration.

解决方案:

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

 

关于spring boot自动注入出现Consider defining a bean of type ‘xxx‘ in your configuration问题解决说明的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Cannot resolve configuration property ''xxxx''、Consider defining a bean of type ''com.*.*.feign.*FeignClient'' in your configuration.、Consider defining a bean of type ''com.lvjing.dao.DeviceStatusMapper'' in your configuration.、Consider defining a bean of type ''org.springframework.data.redis.connection.RedisConnectionFa...的相关信息,请在本站寻找。

本文标签: