将 Spring Boot 版本从 2.0.3.RELEASE 更改为 2.1.0.BUILD-SNAPSHOT 时出现问题 [英] Trouble when changing Spring Boot version from 2.0.3.RELEASE to 2.1.0.BUILD-SNAPSHOT

查看:14
本文介绍了将 Spring Boot 版本从 2.0.3.RELEASE 更改为 2.1.0.BUILD-SNAPSHOT 时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将 Spring Boot 版本从 2.0.3.RELEASE 更改为 2.1.0.BUILD-SNAPSHOT 时,我有一个工作代码停止工作.

I have a working code that stops to work when I change Spring Boot version from 2.0.3.RELEASE to 2.1.0.BUILD-SNAPSHOT.

有时错误是:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

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

Description:

The bean 'dataSource', defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

或...

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-07-16 14:38:18.509 ERROR 604 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

The bean 'scopedTarget.oauth2ClientContext', defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration$SessionScopedConfiguration$ClientContextConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/oauth2/config/annotation/web/configuration/OAuth2ClientConfiguration$OAuth2ClientContextConfiguration.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

这两种情况都与重复的 bean os 其他内容有关.

Both cases it is related to duplicated bean os something else.

我的 POM 依赖项是:

My POM dependencies are:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> 
    </parent>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
        <maven.test.skip>true</maven.test.skip>
    </properties>   


   <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>        
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>       
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>          
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>        
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>


        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
        </dependency>   
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>       


    </dependencies>

和配置:

server:
  error:
    include-stacktrace: always
    whitelabel:
      enabled: false
  servlet:
   session:
    cookie:
     name: HYDRASSESSION
  port: 36205


management:
  endpoints:
    web:
      exposure:
        include: "*"


security:
  basic:
    enabled: false
  oauth2:
      client:
        clientId: atlas
        clientSecret: secret
        accessTokenUri: http://myserverip:36202/oauth/token
        userAuthorizationUri: http://myserverip:36202/oauth/authorize
      resource:
        userInfoUri: http://myserverip:36202/user/me


spring:
  jpa:
    properties:
      hibernate:
        temp:
          use_jdbc_metadata_defaults: false 
    hibernate:
      ddl-auto: validate
  application:
    name: atlas
  datasource:
    password: admin
    username: postgres
    url: jdbc:postgresql://myserverip:36211/atlas?ApplicationName=Atlas

guardiao:
  logout:
    path: http://myserverip:36202/exit

使用 2.0.3.RELEASE 时运行良好,但尝试登录 myserver:36202/oauth/authorize?client_id= 时收到错误:通过浏览器抱怨 ERR_TOO_MANY_REDIRECTS 但我在控制台中没有错误.无论如何......我的问题是:如何将我的 SpringBoot 更新到 2.1.0.BUILD-SNAPSHOT ?

It run fine when using 2.0.3.RELEASE but I'm receiving an error when try to login myserver:36202/oauth/authorize?client_id=: by browser complains ERR_TOO_MANY_REDIRECTS but I have no errors in console. Anyway... my question is: how can I update my SpringBoot to 2.1.0.BUILD-SNAPSHOT ?

推荐答案

所以作为异常报告,有两个相同类型的bean.从历史上看,Spring 会用另一个 bean 覆盖一个 bean.这一直是一个烦恼,因为您很难找到具有完全不同类型但具有相同 bean ID 的第二个 bean 会使您的第一个 bean 消失的错误.

So as the exception reports, there are two beans of the same type. Historically Spring would override one bean with the other. That has long been an annoyance since you could get hard to find bugs where a second bean with a completely different type, but with the same bean ID would make your first bean vanish.

Spring Boot 2 现在默认禁用这种 bean 覆盖.您可以通过在 application.yml 中设置以下属性来重新启用它:

Spring Boot 2 now disables that sort of bean overriding by default. You can re-enable it by setting the following property in your application.yml:

spring.main.allow-bean-definition-overriding: true

这会重新启用之前的行为.它没有解决 bean 被覆盖的根本原因,也意味着您不会从 bean 覆盖错误中受益.随着时间的推移,升级底层库有望解决这个问题.

This re-enables the previous behavior. It doesn't address the root cause that beans are being overridden though and also mean you won't get the benefit of bean override errors. Upgrading the underlying libraries will hopefully clean this up over time.

如其他评论所述,将 spring-security-oauth2-autoconfigure 依赖项升级到 org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.0.RELEASE 可以帮你解决.

As noted on other comments, upgrading the spring-security-oauth2-autoconfigure dependency to org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.0.RELEASE may solve it for you.

这篇关于将 Spring Boot 版本从 2.0.3.RELEASE 更改为 2.1.0.BUILD-SNAPSHOT 时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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