为什么 Spring Ingoring Eclipse 链接源包?
Why is Spring Ingoring a Eclipse Linked Source Package?
我正在为一个使用微服务架构的亲戚开发一个小型 Spring 启动应用程序。由于多个服务将共享一些代码,我创建了一个名为 domain 的项目来存储所有共享的 classes。我创建了另一个项目,称为配置,用于从数据库中检索参数。尝试在 RestController 中注入存储库时,Spring 控制台告诉它找不到要注入的存储库。到目前为止,我已经尝试 link 源项目并在 eclipse 中添加为模块依赖项。我还在应用程序 class 中添加了包扫描,但没有成功。另一方面,外部 classes 编译成功。问题似乎出在导入外部 eclipse 项目时 Spring 依赖注入。
存储库
@Service
public interface ComponentRepository extends JpaRepository<Component, Integer> {
}
控制器
@RestController
public class 配置控制器 {
@Autowired
private ComponentRepository repository;
@GetMapping(path = "/configuration/{component}")
public Optional<Component> getConfiguration(@PathVariable Component component) {
return repository.findById(3);//fixed whitle troubleshooting.
}
}
主应用程序Class
@SpringBootApplication(scanBasePackages = { "ofi.marina.configuration", "ofi.marina.domain" })
public class ConfigurationApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigurationApplication.class, args);
}
}
链接来源和排除项
错误 运行 来自 Maven
2022-03-06 15:52:03.219 INFO 7196 --- [ main] o.m.c.ConfigurationApplication : Starting ConfigurationApplication using Java 17.0.1 on XXXX with PID 7196 (E:\JhonnyOnedrive\OneDrive\Documents\Projects\MarinaOFI\Source\configuration\target\classes started by XXXXX in E:\JhonnyOnedrive\OneDrive\Documents\Projects\MarinaOFI\Source\configuration)
2022-03-06 15:52:03.222 INFO 7196 --- [ main] o.m.c.ConfigurationApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-06 15:52:03.853 INFO 7196 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-03-06 15:52:03.907 ERROR 7196 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.TypeNotPresentException: Type ofi.marina.domain.Component not present
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:na]
at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) ~[na:na]
at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:na]
at java.base/sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68) ~[na:na]
at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138) ~[na:na]
at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:na]
at java.base/sun.reflect.generics.repository.ClassRepository.computeSuperInterfaces(ClassRepository.java:117) ~[na:na]
at java.base/sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:95) ~[na:na]
at java.base/java.lang.Class.getGenericInterfaces(Class.java:1211) ~[na:na]
at org.springframework.core.ResolvableType.getInterfaces(ResolvableType.java:502) ~[spring-core-5.3.16.jar:5.3.16]
at org.springframework.core.GenericTypeResolver.buildTypeVariableMap(GenericTypeResolver.java:271) ~[spring-core-5.3.16.jar:5.3.16]
at org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:248) ~[spring-core-5.3.16.jar:5.3.16]
at org.springframework.data.util.ClassTypeInformation.getTypeVariableMap(ClassTypeInformation.java:115) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.util.ClassTypeInformation.getTypeVariableMap(ClassTypeInformation.java:104) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.util.ClassTypeInformation.<init>(ClassTypeInformation.java:93) ~[spring-data-commons-2.6.2.jar:2.6.2]
at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330) ~[na:na]
at org.springframework.data.util.ClassTypeInformation.from(ClassTypeInformation.java:71) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.core.support.AbstractRepositoryMetadata.<init>(AbstractRepositoryMetadata.java:63) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.core.support.DefaultRepositoryMetadata.<init>(DefaultRepositoryMetadata.java:49) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.core.support.AbstractRepositoryMetadata.getMetadata(AbstractRepositoryMetadata.java:78) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.getRepositoryConfigurations(RepositoryConfigurationExtensionSupport.java:103) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:159) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:62) ~[spring-boot-autoconfigure-2.6.4.jar:2.6.4]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:396) ~[spring-context-5.3.16.jar:5.3.16]
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) ~[na:na]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:395) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:157) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.4.jar:2.6.4]
at ofi.marina.configuration.ConfigurationApplication.main(ConfigurationApplication.java:10) ~[classes/:na]
Caused by: java.lang.ClassNotFoundException: ofi.marina.domain.Component
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ~[na:na]
... 40 common frames omitted
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.715 s
[INFO] Finished at: 2022-03-06T15:52:03-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:run (default-cli) on project configuration: Application finished with exit code: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:run (default-cli) on project configuration: Application finished with exit code: 1
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Application finished with exit code: 1
at org.springframework.boot.maven.RunMojo.runWithForkedJvm(RunMojo.java:101)
at org.springframework.boot.maven.AbstractRunMojo.doRunWithForkedJvm(AbstractRunMojo.java:286)
at org.springframework.boot.maven.AbstractRunMojo.run(AbstractRunMojo.java:251)
at org.springframework.boot.maven.AbstractRunMojo.execute(AbstractRunMojo.java:223)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
... 20 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
错误 运行 来自 Eclipse
Error: Could not find or load main class ofi.marina.configuration.ConfigurationApplication
Caused by: java.lang.ClassNotFoundException: ofi.marina.configuration.ConfigurationApplication
您的包裹不匹配。 class ofi.marina.domain.Component 有这个包:
ofi.marina.domain
但是你的 Spring Boot main class ConfigurationApplication 有一个不同的包 o.m.c。
我猜 o.m.c.ConfigurationApplication 可能是 ofi.marina.cXYZ.ConfigurationApplication。因此,您必须将组件 class 包更改为 ofi.marina.cXYZ.Component。或者使用Spring @Import 加载class不同根包中的es.
所以,我成功了。由于这是今天的宠物项目,我继续修补它。到目前为止,已进行 3 次更改:
- 添加@ComponentScan 扫描其他包
主应用程序Class
@SpringBootApplication
@EntityScan(basePackages = {"ofi.marina.domain"})
@ComponentScan(basePackages = {"ofi.marina.domain"})
public class ParametersApplication {
public static void main(String[] args) {
SpringApplication.run(ParametersApplication.class, args);
}
}
将存储库从@Service 更改为@Component
@组件
public interface ComponentRepository extends JpaRepository {
}
从链接的源中删除了一个 class ,它不应该被包含(可能是这个单独修复了它 IDK。需要更多测试)。
现在我正在重新组织工作区以避免这种糟糕的设计错误。但我希望任何遇到这种情况的人都能找到这个 post.
我正在为一个使用微服务架构的亲戚开发一个小型 Spring 启动应用程序。由于多个服务将共享一些代码,我创建了一个名为 domain 的项目来存储所有共享的 classes。我创建了另一个项目,称为配置,用于从数据库中检索参数。尝试在 RestController 中注入存储库时,Spring 控制台告诉它找不到要注入的存储库。到目前为止,我已经尝试 link 源项目并在 eclipse 中添加为模块依赖项。我还在应用程序 class 中添加了包扫描,但没有成功。另一方面,外部 classes 编译成功。问题似乎出在导入外部 eclipse 项目时 Spring 依赖注入。
存储库
@Service
public interface ComponentRepository extends JpaRepository<Component, Integer> {
}
控制器
@RestController
public class 配置控制器 {
@Autowired
private ComponentRepository repository;
@GetMapping(path = "/configuration/{component}")
public Optional<Component> getConfiguration(@PathVariable Component component) {
return repository.findById(3);//fixed whitle troubleshooting.
}
}
主应用程序Class
@SpringBootApplication(scanBasePackages = { "ofi.marina.configuration", "ofi.marina.domain" })
public class ConfigurationApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigurationApplication.class, args);
}
}
链接来源和排除项
错误 运行 来自 Maven
2022-03-06 15:52:03.219 INFO 7196 --- [ main] o.m.c.ConfigurationApplication : Starting ConfigurationApplication using Java 17.0.1 on XXXX with PID 7196 (E:\JhonnyOnedrive\OneDrive\Documents\Projects\MarinaOFI\Source\configuration\target\classes started by XXXXX in E:\JhonnyOnedrive\OneDrive\Documents\Projects\MarinaOFI\Source\configuration)
2022-03-06 15:52:03.222 INFO 7196 --- [ main] o.m.c.ConfigurationApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-06 15:52:03.853 INFO 7196 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-03-06 15:52:03.907 ERROR 7196 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.TypeNotPresentException: Type ofi.marina.domain.Component not present
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:na]
at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) ~[na:na]
at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:na]
at java.base/sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68) ~[na:na]
at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138) ~[na:na]
at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:na]
at java.base/sun.reflect.generics.repository.ClassRepository.computeSuperInterfaces(ClassRepository.java:117) ~[na:na]
at java.base/sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:95) ~[na:na]
at java.base/java.lang.Class.getGenericInterfaces(Class.java:1211) ~[na:na]
at org.springframework.core.ResolvableType.getInterfaces(ResolvableType.java:502) ~[spring-core-5.3.16.jar:5.3.16]
at org.springframework.core.GenericTypeResolver.buildTypeVariableMap(GenericTypeResolver.java:271) ~[spring-core-5.3.16.jar:5.3.16]
at org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:248) ~[spring-core-5.3.16.jar:5.3.16]
at org.springframework.data.util.ClassTypeInformation.getTypeVariableMap(ClassTypeInformation.java:115) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.util.ClassTypeInformation.getTypeVariableMap(ClassTypeInformation.java:104) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.util.ClassTypeInformation.<init>(ClassTypeInformation.java:93) ~[spring-data-commons-2.6.2.jar:2.6.2]
at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330) ~[na:na]
at org.springframework.data.util.ClassTypeInformation.from(ClassTypeInformation.java:71) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.core.support.AbstractRepositoryMetadata.<init>(AbstractRepositoryMetadata.java:63) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.core.support.DefaultRepositoryMetadata.<init>(DefaultRepositoryMetadata.java:49) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.core.support.AbstractRepositoryMetadata.getMetadata(AbstractRepositoryMetadata.java:78) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.getRepositoryConfigurations(RepositoryConfigurationExtensionSupport.java:103) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:159) ~[spring-data-commons-2.6.2.jar:2.6.2]
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:62) ~[spring-boot-autoconfigure-2.6.4.jar:2.6.4]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:396) ~[spring-context-5.3.16.jar:5.3.16]
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) ~[na:na]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:395) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:157) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.4.jar:2.6.4]
at ofi.marina.configuration.ConfigurationApplication.main(ConfigurationApplication.java:10) ~[classes/:na]
Caused by: java.lang.ClassNotFoundException: ofi.marina.domain.Component
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ~[na:na]
... 40 common frames omitted
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.715 s
[INFO] Finished at: 2022-03-06T15:52:03-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:run (default-cli) on project configuration: Application finished with exit code: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:run (default-cli) on project configuration: Application finished with exit code: 1
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Application finished with exit code: 1
at org.springframework.boot.maven.RunMojo.runWithForkedJvm(RunMojo.java:101)
at org.springframework.boot.maven.AbstractRunMojo.doRunWithForkedJvm(AbstractRunMojo.java:286)
at org.springframework.boot.maven.AbstractRunMojo.run(AbstractRunMojo.java:251)
at org.springframework.boot.maven.AbstractRunMojo.execute(AbstractRunMojo.java:223)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
... 20 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
错误 运行 来自 Eclipse
Error: Could not find or load main class ofi.marina.configuration.ConfigurationApplication
Caused by: java.lang.ClassNotFoundException: ofi.marina.configuration.ConfigurationApplication
您的包裹不匹配。 class ofi.marina.domain.Component 有这个包:
ofi.marina.domain
但是你的 Spring Boot main class ConfigurationApplication 有一个不同的包 o.m.c。
我猜 o.m.c.ConfigurationApplication 可能是 ofi.marina.cXYZ.ConfigurationApplication。因此,您必须将组件 class 包更改为 ofi.marina.cXYZ.Component。或者使用Spring @Import 加载class不同根包中的es.
所以,我成功了。由于这是今天的宠物项目,我继续修补它。到目前为止,已进行 3 次更改:
- 添加@ComponentScan 扫描其他包
主应用程序Class
@SpringBootApplication
@EntityScan(basePackages = {"ofi.marina.domain"})
@ComponentScan(basePackages = {"ofi.marina.domain"})
public class ParametersApplication {
public static void main(String[] args) {
SpringApplication.run(ParametersApplication.class, args);
}
}
将存储库从@Service 更改为@Component
@组件 public interface ComponentRepository extends JpaRepository
{ }
从链接的源中删除了一个 class ,它不应该被包含(可能是这个单独修复了它 IDK。需要更多测试)。
现在我正在重新组织工作区以避免这种糟糕的设计错误。但我希望任何遇到这种情况的人都能找到这个 post.