将Spring Boot版本从2.0.3.RELEASE更改为2.1.0.BUILD-SNAPSHOT时出现问题

Mag*_*o C 27 spring-boot

我有停止的时候,我从改变春节引导版本一起使用工作代码2.0.3.RELEASE2.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
Run Code Online (Sandbox Code Playgroud)

要么 ...

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
Run Code Online (Sandbox Code Playgroud)

这两种情况都与重复的bean os相关.

我的POM依赖项是:

    <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>
Run Code Online (Sandbox Code Playgroud)

和配置:

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
Run Code Online (Sandbox Code Playgroud)

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

che*_*tts 35

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

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

spring.main.allow-bean-definition-overriding: true
Run Code Online (Sandbox Code Playgroud)

这会重新启用以前的行为.它没有解决bean被覆盖的根本原因,也意味着你不会得到bean覆盖错误的好处.升级底层库有望随着时间的推移清理它.

正如其他评论所述,升级spring-security-oauth2-autoconfigure依赖关系org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.0.RELEASE可以为您解决.