将org.springframework.beans.factory.BeanDefinitionStoreException
文件夹而不是相应的jar文件放在类路径中时,出现main
错误。我将.jar与主文件夹中的类文件进行了比较,并且有相同的文件。这是完整的堆栈跟踪。我更改了程序包名称,因为它是一个内部项目,希望它不会引起混淆:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [de.my.app.package.base.AppConfig]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'DbConfig' for bean class [de.my.app.otherpackage.foo.config.DbConfig] conflicts with existing, non-compatible bean definition of same name and class [de.my.app.otherpackage.foo.config.DbConfig]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
at de.my.app.otherpackage.foo.client.Starter.main(Starter.java:39)
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'DbConfig' for bean class [de.my.app.otherpackage.foo.config.DbConfig] conflicts with existing, non-compatible bean definition of same name and class [de.my.app.otherpackage.foo.config.DbConfig]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:320)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:259)
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:137)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:268)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:191)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:272)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:168)
... 8 more
这是我启动应用程序的方式:
public static void main(String[] args) {
new AnnotationConfigApplicationContext(AppConfig.class);
}
AppConfig看起来像这样
package de.my.app.package.base;
@Configuration
@ComponentScan({ "de.my.app.package", "de.my.app.otherpackage.foo" })
public class AppConfig {...}
这是DbConfig
package de.my.app.otherpackage.foo.config;
@Configuration
@PropertySource({"classpath:db.properties"})
@EnableJpaRepositories(
basePackages = "de.my.app.otherpackage.foo.persistence",
entityManagerFactoryRef = "executionEntityManager",
transactionManagerRef = "executionTransactionManager"
)
public class DbConfig {}
现在事情是AppConfig
在项目A中,DbConfig
和main
在项目B中。项目B当然具有项目A作为依赖项。运行java -cp /path/to/lib/of/ProjectB
时没有错误。但是当我运行java -cp /path/to/build/classes/main
时,我得到了错误。