NotFound403 / id-server

An OAuth2 Authorization Server,Based on Spring Authorization Server
Apache License 2.0
400 stars 112 forks source link

启动时找不到注入类 #27

Closed yzbh007 closed 2 years ago

yzbh007 commented 2 years ago

Parameter 1 of constructor in cn.felord.idserver.service.JpaRegisteredClientRepository required a bean of type 'cn.felord.idserver.mapstruct.OAuth2ClientMapper' that could not be found.

NotFound403 commented 2 years ago

@yzbh007 请在提问时注明环境以及相关的细节

yzbh007 commented 2 years ago

ide: Pleiades All in One Eclipse 最新版:pleiades-2022-06-java-win-64bit-jre_20220515 db: mysql 8.0 数据库表能自动创建,demo数据手动插入 jdk: 1.8,11,17都试过同样问题

. _ _ /\ / '_ () \ \ \ \ ( ( )\ | ' | '| | ' \/ ` | \ \ \ \ \/ _)| |)| | | | | || (| | ) ) ) ) ' |__| .|| ||| |\, | / / / / =========|_|==============|__/=//// :: Spring Boot :: (v2.6.6)

2022-06-02 13:15:04.183 INFO 18172 --- [ main] cn.felord.idserver.IdServerApplication : Starting IdServerApplication using Java 1.8.0_332 on DESKTOP-NH82ORQ with PID 18172 (C:\new_denryoku\pleiades-2022-06-java-win-64bit-jre_20220515\workspace\id-server\target\classes started by Administrator in C:\new_denryoku\pleiades-2022-06-java-win-64bit-jre_20220515\workspace\id-server) 2022-06-02 13:15:04.187 INFO 18172 --- [ main] cn.felord.idserver.IdServerApplication : The following 1 profile is active: "mysql" 2022-06-02 13:15:05.077 INFO 18172 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2022-06-02 13:15:05.183 INFO 18172 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 97 ms. Found 15 JPA repository interfaces. 2022-06-02 13:15:05.808 INFO 18172 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http) 2022-06-02 13:15:05.819 INFO 18172 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-06-02 13:15:05.820 INFO 18172 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60] 2022-06-02 13:15:05.927 INFO 18172 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-06-02 13:15:05.927 INFO 18172 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1697 ms 2022-06-02 13:15:06.198 INFO 18172 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2022-06-02 13:15:06.250 INFO 18172 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.7.Final 2022-06-02 13:15:06.448 INFO 18172 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final} 2022-06-02 13:15:06.564 INFO 18172 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2022-06-02 13:15:06.736 INFO 18172 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2022-06-02 13:15:06.755 INFO 18172 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect 2022-06-02 13:15:07.010 WARN 18172 --- [ main] org.hibernate.id.UUIDHexGenerator : HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUIDGenerator instead 2022-06-02 13:15:07.906 INFO 18172 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2022-06-02 13:15:07.916 INFO 18172 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2022-06-02 13:15:08.258 WARN 18172 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authorizationConsentController' defined in file [C:\new_denryoku\pleiades-2022-06-java-win-64bit-jre_20220515\workspace\id-server\target\classes\cn\felord\idserver\endpoint\oauth2\AuthorizationConsentController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jpaRegisteredClientRepository' defined in file [C:\new_denryoku\pleiades-2022-06-java-win-64bit-jre_20220515\workspace\id-server\target\classes\cn\felord\idserver\service\JpaRegisteredClientRepository.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'cn.felord.idserver.mapstruct.OAuth2ClientMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 2022-06-02 13:15:08.259 INFO 18172 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2022-06-02 13:15:08.260 INFO 18172 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2022-06-02 13:15:08.269 INFO 18172 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2022-06-02 13:15:08.271 INFO 18172 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2022-06-02 13:15:08.286 INFO 18172 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2022-06-02 13:15:08.307 ERROR 18172 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Parameter 1 of constructor in cn.felord.idserver.service.JpaRegisteredClientRepository required a bean of type 'cn.felord.idserver.mapstruct.OAuth2ClientMapper' that could not be found.

Action:

Consider defining a bean of type 'cn.felord.idserver.mapstruct.OAuth2ClientMapper' in your configuration.

NotFound403 commented 2 years ago

提示OAuth2ClientMapper没有注入Spring IoC,编译代码,看一下会不会生成带@Component注解的实现类OAuth2ClientMapperImpl

yzbh007 commented 2 years ago

问题解决了。 找不到注入类是因为通过eclipse菜单的clean...编译工程后,\target\classes\cn\felord\idserver\mapstruct里没有生成带@Component注解的实现类OAuth2ClientMapperImpl,直接通过STS插件dashboard启动springboot工程,就会报错。 改成通过maven方式执行springboot:run, 就可以编译生成OAuth2ClientMapperImpl,正常启动工程。 图片