java - 启动 Tomcat 时 Web 模块没有从核心模块中找到类

标签 java spring maven tomcat

我有一个项目,目前由两个模块组成,一个网络模块和一个核心模块,网络模块在我的 pom.xml 中具有核心作为依赖项。我正在使用 Spring,并且每个模块都有一个单独的 Spring 配置类(Web Spring 配置导入核心 Spring 配置)。为了加载 Spring 上下文,我使用了 WebApplicationInitializer,它首先加载 web Spring 配置。

但是,在启动服务器(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 方法运行一个简单的类,在该方法中我从我的核心模块实例化了一个类,这次没有抛出任何异常。

在我看来,我的 web 模块不知道我的核心模块,但只有在使用 Tomcat 时才知道。我认为在 pom 中放置依赖项就足够了,但看来我错了。感谢您的帮助。

最佳答案

我不知道这是否是最好的方法,但以下方法对我有用:

在 Eclipse 中 Tomcat 的服务器配置中:

  1. 点击打开启动配置
  2. Classpath 选项卡上,将我的核心模块添加到User Entries

在我的网络模块中:

  1. 打开属性窗口;
  2. 部署程序集上,添加了我的核心模块;

关于java - 启动 Tomcat 时 Web 模块没有从核心模块中找到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33359126/

相关文章:

java - 如何使用bulkUpdate批量删除

java - 无法从字符串值实例化类型 [简单类型,类 java.time.LocalDate] 的值

java - 如何编写多正则表达式行?

java - Volley每次从SERVER而不是缓存获取数据

java - 从 Java 中的 Spark 数据集中获取唯一单词

spring - 通过示例进行Spring Boot和Logback

java - Maven 依赖项在 eclipse java 构建路径中不可用

java - Hibernate 抛出 java.lang.NoClassDefFoundError : org/hibernate/internal/CoreMessageLogger

java - Spark2.2.1 不兼容 Jackson 版本 2.8.8

java - 我的 Java 程序如何在其 .jar 文件中存储文件?