构建Spring引导API后,java类路径不正确
我正在忍受一个与我的Spring Boot微服务相关的小问题,我最近移动了我的主服务器。java文件(包含main方法)保存到一个单独的包中,但是这会导致问题,因此我必须将其还原到最初创建项目时的原始位置
这是我的堆栈跟踪上的错误
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$RepositoryAnnotationTransactionAttributeSource.<init>(TransactionalRepositoryProxyPostProcessor.java:111)
The following method did not exist:
'void org.springframework.transaction.annotation.AnnotationTransactionAttributeSource.<init>(boolean)'
The method's class, org.springframework.transaction.annotation.AnnotationTransactionAttributeSource, is available from the following locations:
jar:file:/C:/Users/Engineering/.gradle/caches/modules-2/files-2.1/org.springframework/spring-dao/1.2.9/6f90baf86fc833cac3c677a8f35d3333ed86baea/spring-dao-1.2.9.jar!/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.class
jar:file:/C:/Users/Engineering/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.3.9-SNAPSHOT/d8f8af631e6429037c39f756fe2279f50c636844/spring-tx-5.3.9-SNAPSHOT.jar!/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.class
The class hierarchy was loaded from the following locations:
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource: file:/C:/Users/Engineering/.gradle/caches/modules-2/files-2.1/org.springframework/spring-dao/1.2.9/6f90baf86fc833cac3c677a8f35d3333ed86baea/spring-dao-1.2.9.jar
org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource: file:/C:/Users/Engineering/.gradle/caches/modules-2/files-2.1/org.springframework/spring-dao/1.2.9/6f90baf86fc833cac3c677a8f35d3333ed86baea/spring-dao-1.2.9.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
Process finished with exit code 1
这是我最初做的
我最初在我的主目录中创建了一个名为Run的新文件夹,并放置了我的DemoApplication,该类包含main方法。但是,这会导致问题,因为它无法检测到我的控制器(调用我的端点会出现404 not found错误)
因此,我决定删除Run包并将DemoApplication类单独放入src->;主文件夹
当前的文件结构
在此之前,DemoApplication被放在名为Run的包中
最后这是我的身材。格拉德尔
plugins {
id 'org.springframework.boot' version '2.4.9-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
ext {
set('springCloudGcpVersion', "2.0.3")
set('springCloudVersion', "2020.0.3")
}
dependencies {
implementation 'com.google.cloud:spring-cloud-gcp-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// https://mvnrepository.com/artifact/org.springframework/spring-hibernate
implementation group: 'org.springframework', name: 'spring-hibernate', version: '1.2.9'
runtimeOnly 'mysql:mysql-connector-java'
compile 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.3.0'
}
dependencyManagement {
imports {
mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:${springCloudGcpVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
还有我的演示应用程序。java类
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication(scanBasePackages = {"com.example.demo","com.example.demo.Controllers","com.example.demo.model","com.example.demo.Services","com.example.demo.Respository"})
@EnableJpaRepositories("com.example.demo.Respository")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
共 (0) 个答案