spring-boot - spring-boot-starter-parent 版本 2 与 spring-security-jwt 和 spring-security-oauth2 之间是否有冲突

标签 spring-boot spring-boot-starter

我正在尝试解决我在 Spring Boot + Java 8 和 Hibernate 方面遇到的问题(我最初关于此问题的问题是 org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value did not match expected type java.time.LocalDateTime )。

自从我阅读《Since 5.2》以来,“hibernate-java8 模块已合并到 hibernate-core 中,并且现在原生支持 Java 8 日期/时间类型。”来自How to persist JSR-310 types with Spring Data JPA? ,我尝试将所有 Spring Boot 依赖项更新为最新版本。

我的意思是,我的父 pom 之前是:

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

我改为

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

这样做的目的是利用上面提到的“...现在原生支持...”,假设它可以解决我可能面临的日期时间冲突。

现在我面临另一个问题

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-jwt</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
</dependency>

说:项目构建错误:org.springframework.security.oauth:spring-security-oauth2:jar 的“dependency.dependency.version”是 缺失(与 org.springframework.security:spring-security-jwt:jar 相同)。

如何解决 org.springframework.security:spring-security-jwt:jar 和 org.springframework.security.oauth:spring-security-oauth2:jar 的特定问题?

***已编辑,在我更改上述版本后,我得到了

 :: Spring Boot ::        (v1.5.6.RELEASE)

2018-03-26 17:53:10.490  INFO 1161 --- [  restartedMain] br.com.moving.MovingApiApplication       : Starting MovingApiApplication on fulls-iMac.home with PID 1161 (/Users/accountname/WSs/ws_servicos_prontos/api-moving/target/classes started by accountname in /Users/accountname/WSs/ws_servicos_prontos/api-moving)
2018-03-26 17:53:10.492  INFO 1161 --- [  restartedMain] br.com.moving.MovingApiApplication       : The following profiles are active: ${envspring}
2018-03-26 17:53:10.607  INFO 1161 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64f45797: startup date [Mon Mar 26 17:53:10 BRT 2018]; root of context hierarchy
2018-03-26 17:53:11.879  INFO 1161 --- [  restartedMain] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'commandLineRunner' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=apiSecurityApplication; factoryMethodName=commandLineRunner; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [br/com/moving/ApiSecurityApplication.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=movingApiApplication; factoryMethodName=commandLineRunner; initMethodName=null; destroyMethodName=(inferred); defined in br.com.moving.MovingApiApplication]
2018-03-26 17:53:12.276  INFO 1161 --- [  restartedMain] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2018-03-26 17:53:13.017  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$501c7c5b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.096  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$e8ca4495] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.110  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.115  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@616c515f' of type [org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.122  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$d9ee747] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.157  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.212  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.218  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration$$EnhancerBySpringCGLIB$$766385b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.254  INFO 1161 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'resourceServerProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.831  INFO 1161 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9000 (http)
2018-03-26 17:53:13.847  INFO 1161 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-03-26 17:53:13.848  INFO 1161 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.16
2018-03-26 17:53:13.972  INFO 1161 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-03-26 17:53:13.972  INFO 1161 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3368 ms
2018-03-26 17:53:14.201  INFO 1161 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-26 17:53:14.203  INFO 1161 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-03-26 17:53:14.203  INFO 1161 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-03-26 17:53:14.263  WARN 1161 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "${envspring}" are currently active).
2018-03-26 17:53:14.270  INFO 1161 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-03-26 17:53:14.298  INFO 1161 --- [  restartedMain] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-03-26 17:53:14.303 ERROR 1161 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "${envspring}" are currently active).

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.743 s
[INFO] Finished at: 2018-03-26T17:53:14-03:00
[INFO] ------------------------------------------------------------------------

当我为 spring-boot-starter-parent 设置 2.0.0.RELEASE 时,在日志中看到 v1.5.6.RELEASE 听起来很奇怪

最佳答案

Spring Boot 2.0 migration指南说的是

Functionality from the Spring Security OAuth project is being migrated to core Spring Security. Dependency management is no longer provided for that dependency and Spring Boot 2 provides OAuth 2.0 client support via Spring Security 5.

因此您应该手动指定 jwt 和 oauth2 依赖项。

    <spring-security-oauth2.version>2.3.3.RELEASE</spring-security-oauth2.version>
    <spring-security-jwt.version>1.0.9.RELEASE</spring-security-jwt.version>

    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>${spring-security-oauth2.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-jwt</artifactId>
        <version>${spring-security-jwt.version}</version>
    </dependency>

关于spring-boot - spring-boot-starter-parent 版本 2 与 spring-security-jwt 和 spring-security-oauth2 之间是否有冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49499743/

相关文章:

java - 在执行 POST 请求时,如何将子项保存在现有父项中?

java - Spring Data JPA 查询返回 null

spring - 无法自动接线 `WebTestClient` - 没有自动配置

java - spring如何在内部使用_csrf参数或X-CSRF-TOKEN header 验证csrf token ?

java - 替换 Servlet Filter 中的响应内容

java - 如何在集成测试时使自定义 Spring Boot 启动器可加载?

spring-boot - 在类路径中具有 "spring-boot-starter-test"依赖项时无法启动 tomcat 服务器

java - Controller 中扩展抽象 Controller 的方法的自定义注释