2015-10-27 82 views
1

我有一個當前由兩個模塊組成的項目,一個web模塊和一個核心模塊,web模塊的核心作爲我的pom中的依賴項。我使用的是Spring,並且我爲每個模塊都有一個單獨的Spring配置類(Web Spring配置導入核心Spring配置)。爲了加載Spring上下文,我使用了一個WebApplicationInitializer,它通過加載Web Spring配置開始。啓動Tomcat時,Web模塊找不到來自核心模塊的類

然而,在啓動服務器(Apache Tomcat上8.0),會出現以下錯誤:

INFO: Initializing Spring root WebApplicationContext 
Oct 26, 2015 11:40:03 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
INFO: Root WebApplicationContext: initialization started 
Oct 26, 2015 11:40:03 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh 
INFO: Refreshing Root WebApplicationContext: startup date [Mon Oct 26 23:40:03 BRST 2015]; root of context hierarchy 
Oct 26, 2015 11:40:03 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions 
INFO: Registering annotated classes: [class br.com.liabilis.ep.config.spring.WebSpringConfig] 
Oct 26, 2015 11:40:03 PM org.springframework.core.annotation.AnnotationUtils handleIntrospectionFailure 
INFO: Failed to introspect annotations on [class br.com.liabilis.ep.config.spring.WebSpringConfig]: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 
Oct 26, 2015 11:40:03 PM org.springframework.core.annotation.AnnotationUtils handleIntrospectionFailure 
INFO: Failed to introspect annotations on [class br.com.liabilis.ep.config.spring.WebSpringConfig]: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 
Oct 26, 2015 11:40:03 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
SEVERE: Context initialization failed 
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) 
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) 
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) 
    at java.lang.Class.createAnnotationData(Class.java:3513) 
    at java.lang.Class.annotationData(Class.java:3502) 
    at java.lang.Class.getAnnotations(Class.java:3438) 
    at org.springframework.core.type.StandardAnnotationMetadata.getAnnotationTypes(StandardAnnotationMetadata.java:73) 
    at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:87) 
    at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:70) 
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:146) 
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:127) 
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:122) 
    at org.springframework.web.context.support.AnnotationConfigWebApplicationContext.loadBeanDefinitions(AnnotationConfigWebApplicationContext.java:211) 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:604) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:509) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4736) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

Oct 26, 2015 11:40:03 PM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) 
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) 
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) 
    at java.lang.Class.createAnnotationData(Class.java:3513) 
    at java.lang.Class.annotationData(Class.java:3502) 
    at java.lang.Class.getAnnotations(Class.java:3438) 
    at org.springframework.core.type.StandardAnnotationMetadata.getAnnotationTypes(StandardAnnotationMetadata.java:73) 
    at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:87) 
    at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:70) 
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:146) 
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:127) 
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:122) 
    at org.springframework.web.context.support.AnnotationConfigWebApplicationContext.loadBeanDefinitions(AnnotationConfigWebApplicationContext.java:211) 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129) 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:604) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:509) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4736) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

後來,我試着從WebApplicationInitializer在我的核心模塊實例化一個簡單的類並重新啓動服務器,它扔一個ClassNotFoundException

我也嘗試了用main方法運行一個簡單的類,其中我從我的核心模塊實例化了一個類,這次沒有拋出異常。

在我看來,我的網站模塊不知道我的核心模塊,但只有當使用Tomcat。我認爲在pom中放置一個依賴關係就足夠了,但似乎我錯了。任何幫助表示讚賞。

回答

1

我不知道這是否是最好的方式,但對我下面的工作:

在Eclipse Tomcat的服務器配置:

  1. 點擊了打開勞克配置;我的核心模塊添加到用戶條目;

在我的Web模塊:

  1. 拉開屬性窗口;
  2. 部署組裝,加入我的核心模塊;