鍍金池/ 問答/人工智能  Java  Office/ Spring boot啟動時報錯

Spring boot啟動時報錯

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

2018-05-30 10:03:51.252  INFO 6448 --- [  restartedMain] com.example.DemoApplication              : Starting DemoApplication on huyh-PC with PID 6448 (D:\work\springbootspace\demo\target\classes started by huyh in D:\work\springbootspace\demo)
2018-05-30 10:03:51.254  INFO 6448 --- [  restartedMain] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2018-05-30 10:03:51.775  INFO 6448 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@5d4441ea: startup date [Wed May 30 10:03:51 CST 2018]; root of context hierarchy
2018-05-30 10:03:53.404  WARN 6448 --- [  restartedMain] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.example]' package. Please check your configuration.
2018-05-30 10:03:53.509  INFO 6448 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-05-30 10:03:54.092  INFO 6448 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$5cc6f725] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-05-30 10:03:54.107  INFO 6448 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cache.annotation.ProxyCachingConfiguration' of type [org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$a5d92d43] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-05-30 10:03:54.840  INFO 6448 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-05-30 10:03:54.885  INFO 6448 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-05-30 10:03:54.885  INFO 6448 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-05-30 10:03:54.890  INFO 6448 --- [ost-startStop-1] 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: [D:\work\JDK\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\work\JDK\bin;D:\work\SVN\bin;C:\Program Files (x86)\Git\cmd;%TOMCAT_HOME%\bin;D:\work\tomcat7\lib;D:\work\JDK\bin;D:\work\JDK\jre\bin;.]
2018-05-30 10:03:55.634  INFO 6448 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-05-30 10:03:55.634  INFO 6448 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3864 ms
2018-05-30 10:03:56.250  INFO 6448 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-05-30 10:03:56.259  INFO 6448 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-05-30 10:03:56.260  INFO 6448 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-05-30 10:03:56.261  INFO 6448 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-05-30 10:03:56.262  INFO 6448 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
2018-05-30 10:03:56.854  WARN 6448 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisCacheTransfer': Unsatisfied dependency expressed through method 'setJedisConnectionFactory' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2018-05-30 10:03:56.869  INFO 6448 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-05-30 10:03:56.885  INFO 6448 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-30 10:03:57.077 ERROR 6448 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Parameter 0 of method setJedisConnectionFactory in com.example.Utils.cache.RedisCacheTransfer required a bean of type 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory' that could not be found.
    - Bean method 'redisConnectionFactory' in 'JedisConnectionConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.data.redis.connection.RedisConnectionFactory; SearchStrategy: all) found beans of type 'org.springframework.data.redis.connection.RedisConnectionFactory' redisConnectionFactory


Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory' in your configuration.


Process finished with exit code 0

剛接觸spring boot在用redis做二級緩存的時候,依照往上的例子做的,結(jié)果啟動的時候就報這個錯誤!
pom依賴

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

然后下面是application的

#redis
spring.redis.database=1
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1
spring.redis.timeout=50000
#數(shù)據(jù)庫配置
mybatis.mapperLocations=classpath:mappers/*.xml
mybatis.type-aliases-package= com.example.entity
mybatis.config-location= classpath:mybatis-config.xml

#全局映射器啟用緩存 *主要將此屬性設(shè)置完成即可
mybatis.cacheEnabled=true
#查詢時,關(guān)閉關(guān)聯(lián)對象即時加載以提高性能
mybatis.lazyLoadingEnabled=false
#對于未知的SQL查詢,允許返回不同的結(jié)果集以達到通用的效果
mybatis.multipleResultSetsEnabled=true
#設(shè)置關(guān)聯(lián)對象加載的形態(tài),此處為按需加載字段(加載字段由SQL指 定),不會加載關(guān)聯(lián)表的所有字段,以提高性能
mybatis.aggressiveLazyLoading=true

#pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

spring.datasource.url = jdbc:mysql://localhost:3306/exam
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName =com.mysql.jdbc.Driver
spring.datasource.max-active=20
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10

報錯類


@Component
public class RedisCacheTransfer {

    @Autowired
    public void setJedisConnectionFactory(JedisConnectionFactory jedisConnectionFactory) {
        MybatisRedisCache.setJedisConnectionFactory(jedisConnectionFactory);
    }

}

然后啟動的時候就是這個錯

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

Description:

Parameter 0 of method setJedisConnectionFactory in com.example.Utils.cache.RedisCacheTransfer required a bean of type 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory' that could not be found.
    - Bean method 'redisConnectionFactory' in 'JedisConnectionConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.data.redis.connection.RedisConnectionFactory; SearchStrategy: all) found beans of type 'org.springframework.data.redis.connection.RedisConnectionFactory' redisConnectionFactory


Action:

Consider revisiting the conditions above or defining a bean of type 'org.springframework.data.redis.connection.jedis.JedisConnectionFactory' in your configuration.


Process finished with exit code 0

我也不知道我貼的這些夠不夠大佬們分析問題,如果想看哪里我可以再貼上來

回答
編輯回答
來守候

不知在該類中是否有JedisConnectionFactory變量,其實如果你使用了@Component注解了之后,你可以直接在該類中直接使用@AutoWired直接注入

@Component
public class RedisCacheTransfer {
    @Autowired
    private JedisConnectionFactory jedisConnectionFactory
    
}

這樣寫不是更加優(yōu)美?
如果你想將該類注冊到MybatisRedisCache中進行設(shè)置,則你可以在你的conifg文件中,當SpringBoot啟動的時候在Mybatis配置方法中加入方法即可

2018年5月31日 07:04
編輯回答
安于心

原因如 @喵了個咪 所說,Spring-boot 2.0 默認使用redis client是lettuce

解決辦法

想試試lettuce:

把JedisConnectionFactory依賴替換為org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory或者org.springframework.data.redis.connection.RedisConnectionFactory

推薦后者,它是JedisConnectionFactory和LettuceConnectionFactory都實現(xiàn)的接口,好處是哪天你想換個redis client可以只改項目依賴而不用動Java代碼

想換成jedis:

排除lettuce依賴,引入jedis

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>io.lettuce</groupId>
                    <artifactId>lettuce-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

或者用spring-boot 1.x也可以

2018年3月13日 01:19
編輯回答
懷中人

去掉jedis,2.0默認用的是lettuce連接Redis

2018年7月27日 00:09
編輯回答
來守候

這個問題解決了嗎?我也遇到這個問題了--萌新一位

2017年2月18日 17:28
編輯回答
柒槿年

錯誤提示注入的時候找不著類型為org.springframework.data.redis.connection.jedis.JedisConnectionFactory的bean,
在你@Configuration配置類里面,用@Bean自己先注冊一個這樣的bean

2017年11月15日 03:34