BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/<NONE>]

守給你的承諾、 提交于 2020-08-09 08:49:11

问题


I have an Apache Camel v3.3 project that works fine as a stand-alone application but I'm struggling to deploy it to Tomcat.

The error I get is:

Jul 06, 2020 5:53:49 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/<NONE>]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/<NONE>]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:637)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5128)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5653)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1327)
    at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:685)
    at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:209)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:141)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:109)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:604)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:165)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1201)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/<NONE>]
    at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:159)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:333)
    ... 46 more

The pom.xml is:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <!--Get required dependencies from parent -->
    <parent>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-dependencies</artifactId>
        <version>3.3.0</version>
    </parent>

    <groupId>commissionly.io</groupId>
    <artifactId>c10y-integration-java</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <java.version>11</java.version>
        <camel.version>3.3.0</camel.version>
        <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
        <spring-boot.version>2.2.7.RELEASE</spring-boot.version>
        <run.profiles>dev</run.profiles>
    </properties>

    <dependencyManagement>
        <dependencies>

            <!--Import as a pom to let spring-boot to manage spring-boot dependency 
                versions -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!--Import as a pom to let camel to manage camel-spring-boot dependency 
                versions -->
            <dependency>
                <groupId>org.apache.camel.springboot</groupId>
                <artifactId>camel-spring-boot-dependencies</artifactId>
                <version>${camel.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <dependencies>
    
        <!-- Camel Starter -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
        </dependency>

        <!-- Component: Serve HTTP requests by a Servlet. -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-servlet-starter</artifactId>
        </dependency>

        <!-- Data format: Marshal POJOs to JSON and back -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-jackson-starter</artifactId>
        </dependency>

        <!-- Component: Not in List of Starters https://camel.apache.org/camel-spring-boot/latest/list.html -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-core-starter</artifactId>
        </dependency>

        <!-- Component: Send requests to external HTTP servers using Apache HTTP Client 4.x. -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-http-starter</artifactId>
        </dependency>

        <!-- Component: Log messages to the underlying logging mechanism. -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-log-starter</artifactId>
        </dependency>

        <!-- Component: Perform SQL queries using Spring JDBC. -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-sql-starter</artifactId>
        </dependency>

        <!-- Component: Access databases through SQL and JDBC. -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-jdbc-starter</artifactId>
        </dependency>
    
        <!--Spring boot dependencies to enable WEB, JDBC and TOMCAT features -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!-- https://www.javacodegeeks.com/2019/04/deploy-spring-boot-application-tomcat.html -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    
        <!-- Component: Expose HTTP endpoints using the HTTP server available in the current platform. -->
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-platform-http-starter</artifactId>
        </dependency>

        <!-- Use CXF HTTP transport to run Camel in Tomcat -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
        </dependency>

        <!-- For Hortio console to detect Camel Context -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-management</artifactId>
        </dependency>

        <!-- MySQL JDBC connector -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.20</version>
            <scope>runtime</scope>
        </dependency>

        <!-- SQL Server JDBC driver -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>8.2.2.jre11</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Required for Base64 encoding -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>

    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <!-- version>${maven-compiler-plugin.version}</version -->
                <configuration>
                    <source>${java.version>}</source>
                    <target>${java.version>}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

The web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

<!-- 
    Angelo Immediata comment: only Spring DispatcherServlet 'dispatcherServlet' is required.
    See https://stackoverflow.com/questions/47651035/spring-context-initialization-failed-even-after-well-defining-the-classpath
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 -->
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
 
 </web-app>

I've tried with and without ContextLoaderListener; the same error is raised.

My code is entirely @Annotated so I have no apache-config or spring-config files.

How can I prevent the startup in Tomcat from trying to read a file that doesn't exist - I guess that's what [/<NONE>] means? - because the file's not necessary.

My goal is to run my Camel app in Tomcat so I can use Hawtio Console for observation & management.


回答1:


I think the issue might be due to the missing tag which defines the location of the camel XMl files. Please check the official guide here

Also, if you want to monitor camel using hawtio, you can do it even without deploying it to Tomcat with the help of jolokia. You need pass JVM arg -javaagent: and run hawtio in standalone mode.



来源:https://stackoverflow.com/questions/62761318/beandefinitionstoreexception-ioexception-parsing-xml-document-from-servletconte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!