在更新我的Spring Boot应用程序到版本3后,将jdk11更新到jdk17启动应用程序后,出现以下错误:
coba. fxmmm . liventing .user. defaultpermissionservice中构造函数的参数0需要一个类型为'com.app.user.repositories '的bean。无法找到PermissionRepository'。行动:考虑定义一个类型为"com.app.user.repositories"的bean。PermissionRepository'
My Repository是这样的:
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PermissionRepository extends JpaRepository<PermissionEntity, Long> {
List<PermissionEntity> findPermissionByUserID(UserEntity userEntityId);
}
My Entity like this:
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.FieldDefaults;
import org.hibernate.Hibernate;
import java.util.Objects;
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Entity
@Table(name = "permission")
public class PermissionEntity {
@Id
@Column(name = "permission_id", nullable = false)
long permissionId;
@ManyToOne
@JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
UserEntity userID;
@Column(name = "ot_broker_id")
long otBrockerId;
@ManyToOne
@JoinColumn(name = "enq_group_id", referencedColumnName = "enq_group_id", nullable = false)
EnquiryGroup enquiryGroupId;
@Column(name = "legal_entity_code")
String legalEntityCode;
@Column(name = "access_code")
String accessCode;
@Column(name = "access_structure")
String accessStructure;
@Column(name = "permission_type")
long permissionType;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
return false;
}
PermissionEntity permission = (PermissionEntity) o;
return Objects.equals(permissionId, permission.permissionId);
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
在我的pom.xml中我有以下依赖项:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
<spring-boot-starter-web.version>3.0.5</spring-boot-starter-web.version>
<spring-webflux.version>6.0.7</spring-webflux.version>
<spring-security-core.version>6.0.2</spring-security-core.version>
<spring-security-web.version>6.0.2</spring-security-web.version>
<springdocopenapi.version>2.0.4</springdocopenapi.version>
<modelmapper.version>2.4.5</modelmapper.version>
<lombok.version>1.18.26</lombok.version>
<git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
<gson.version>2.9.1</gson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</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-validation</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>${modelmapper.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdocopenapi.version}</version>
</dependency>
<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<!-- <version>${junit.version}</version>-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<!-- <version>${junit.version}</version>-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<!-- <version>${spring-security-core.version}</version>-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<!-- <version>${mockwebserver.version}</version>-->
<scope>test</scope>
</dependency>
</dependencies>
我也使用flyway迁移与我的脚本在src/main/resources/db/migration
和在我的应用程序。我已经设置了
spring:
jpa:
database-platform: org.hibernate.dialect.OracleDialect
show-sql: true
open-in-view: true
datasource:
url: ${database_url} # jdbc:oracle:thin:@server1.domain.com:1521/DEV
username: ${user}
password: ${password}
driver-class-name: oracle.jdbc.OracleDriver
flyway:
locations: classpath:db/migration
使用- logging.level.org.springframework=TRACE命令启动应用程序后,我看到如下stacktrace:
java.lang.NoClassDefFoundError: liquibase/exception/ChangeLogParseException
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?]
at java.lang.Class.getConstructors(Class.java:2060) ~[?:?]
at org.springframework.core.io.support.SpringFactoriesLoader$FactoryInstantiator.findConstructor(SpringFactoriesLoader.java:404) ~[spring-core-6.0.7.jar:6.0.7]
java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingFailureAnalyzer
at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
TRACE 14020 --- [ main] o.s.b.d.FailureAnalyzers : FailureAnalyzer org.springframework.boot.autoconfigure.jooq.NoDslContextBeanFailureAnalyzer@349f3ff7 failed
java.lang.NoClassDefFoundError: org/jooq/DSLContext
at org.springframework.boot.autoconfigure.jooq.NoDslContextBeanFailureAnalyzer.analyze(NoDslContextBeanFailureAnalyzer.java:39) ~[spring-boot-autoconfigure-3.0.5.jar:3.0.5]
at org.springframework.boot.autoconfigure.jooq.NoDslContextBeanFailureAnalyzer.analyze(NoDslContextBeanFailureAnalyzer.java:28) ~[spring-boot-autoconfigure-3.0.5.jar:3.0.5]
java.lang.NoClassDefFoundError: io/r2dbc/spi/ConnectionFactory
at org.springframework.boot.autoconfigure.r2dbc.NoConnectionFactoryBeanFailureAnalyzer.analyze(NoConnectionFactoryBeanFailureAnalyzer.java:49) ~[spring-boot-autoconfigure-3.0.5.jar:3.0.5]
at org.springframework.boot.autoconfigure.r2dbc.NoConnectionFactoryBeanFailureAnalyzer.analyze(NoConnectionFactoryBeanFailureAnalyzer.java:34) ~[spring-boot-autoconfigure-3.0.5.jar:3.0.5]
Caused by: java.lang.ClassNotFoundException: io.r2dbc.spi.ConnectionFactory
at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
... 11 more
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.app.user.repositories.PermissionRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1824) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1383) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:245) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1189) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.0.7.jar:6.0.7]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:917) ~[spring-context-6.0.7.jar:6.0.7]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) ~[spring-context-6.0.7.jar:6.0.7]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.5.jar:3.0.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-3.0.5.jar:3.0.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-3.0.5.jar:3.0.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[spring-boot-3.0.5.jar:3.0.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[spring-boot-3.0.5.jar:3.0.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[spring-boot-3.0.5.jar:3.0.5]
我真的不知道为什么会发生这种情况,在我更改spring boot版本和jdk版本之前,一切都很好。
我错过了什么?
任何帮助都非常感谢!
我尝试删除flyway迁移脚本和包,我将数据库连接的url更改为错误的,将ojdbc版本从ojdbc8升级为ojdbc11。
我改变了所有的javax。坚持到雅加达。坚持进口。
我试图用enablejparepository注释启用JPARepos,但它没有像我预期的那样工作,而且我以前不需要使用这个,因为我的Repos发现没有问题。
几个小时后,我发现了这个问题:在依赖项spring-boot-starter-jdbc
中,我添加了范围test
。删除它可以修复这个问题,并且可以再次找到存储库:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<!--<scope>test</scope>-->
</dependency>