spring-boot-starter-parent版本2和spring-security-jwt以及spring-security-oauth2

时间:2018-03-26 20:04:22

标签: spring-boot spring-boot-starter

我正在尝试解决我在使用Spring Boot + Java 8和Hibernate时遇到的问题(我原来的问题是这个问题是org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value did not match expected type java.time.LocalDateTime)。

自从我阅读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的'dependencies.dependency.version':spring-security-oauth2:jar是  缺失(对于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

1 个答案:

答案 0 :(得分:3)

Spring Boot 2.0 migration指南说

  

Spring Security OAuth项目的功能正在迁移到核心Spring Security。不再为该依赖项提供依赖关系管理,Spring Boot 2通过Spring Security 5提供OAuth 2.0客户端支持。

因此,您应手动指定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>