无法打开ServletContext资源[/WEB-INF/dispatcher-servlet.xml]

时间:2018-07-10 21:27:05

标签: java spring weblogic web.xml dispatcher

我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

我的 dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package = "mvc"/>
    <mvc:annotation-driven/>
    <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name = "prefix" value = "/WEB-INF/pages/" />
        <property name = "suffix" value = ".jsp" />
    </bean>
    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties"/>
    </bean>
    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driver}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.user}"/>
        <property name="password" value="${database.password}"/>
    </bean>

    <bean id = "jdbcTemplate" class = "org.springframework.jdbc.core.JdbcTemplate">
        <property name = "dataSource" ref = "dataSource"/>
    </bean>

    <bean id = "dao" class = "mvc.dao.DAOImpl">
        <property name = "template" ref = "jdbcTemplate"/>
    </bean>

    <bean id = "daoStudent" class = "mvc.dao.daoimplementation.DAOStudentImpl">
        <property name = "template" ref = "jdbcTemplate"/>
    </bean>
    <bean id = "daoObject" class = "mvc.dao.daoimplementation.DAOObjectImpl">
        <property name = "template" ref = "jdbcTemplate"/>
    </bean>
    <bean id = "daoLecturer" class = "mvc.dao.daoimplementation.DAOLecturerImpl">
        <property name = "template" ref = "jdbcTemplate"/>
    </bean>

    <bean id = "daoMark" class = "mvc.dao.daoimplementation.DAOMarkImpl">
        <property name = "template" ref = "jdbcTemplate"/>
    </bean>
    <bean id = "daoSubject" class = "mvc.dao.daoimplementation.DAOSubjectImpl">
        <property name = "template" ref = "jdbcTemplate"/>
    </bean>

    <bean id = "daoLesson" class = "mvc.dao.daoimplementation.DAOLessonImpl">
        <property name = "template" ref = "jdbcTemplate"/>
    </bean>
</beans>

项目结构
enter image description here
在Weblogic上部署应用程序时,它会崩溃并显示以下错误

<11.07.2018 0:11:29,387 EEST> <[STANDBY] ExecuteThread:队列的'4':'weblogic.kernel.Default(自我调整)'> <> <> <5f96a035-f431-4eb1-8b1e-92458ce46cdd -00000007> <1531257089387> <[severity-value:8] [rid:0] [partition-id:0] [partition-name:DOMAIN]>

org.springframework.beans.factory.BeanDefinitionStoreException:IOException从ServletContext资源[/WEB-INF/dispatcher-servlet.xml]解析XML文档;嵌套的异常是java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/dispatcher-servlet.xml]     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:223)处     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:194)处     在org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)     在org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)     在org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)     在org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:621)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)     在org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:672)     在org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:638)     在org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:686)     在org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:554)     在org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)     在org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)     在javax.servlet.GenericServlet.init(GenericServlet.java:244)     在weblogic.servlet.internal.StubSecurityHelper $ ServletInitAction.run(StubSecurityHelper.java:343)     在weblogic.servlet.internal.StubSecurityHelper $ ServletInitAction.run(StubSecurityHelper.java:294)     在weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)     在weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)     在weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)     在weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)     在weblogic.servlet.internal.StubSecurityHelper.initServletInstance(StubSecurityHelper.java:99)     在weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:87)     在weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:71)     在weblogic.servlet.internal.StubLifecycleHelper。(StubLifecycleHelper.java:57)     在weblogic.servlet.internal.StubLifecycleHelper。(StubLifecycleHelper.java:31)     在weblogic.servlet.internal.ServletStubImpl.initStubLifecycleHelper(ServletStubImpl.java:673)     在weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:612)     在weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:2064)     在weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:2041)     在weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1930)     在weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3101)     在weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1843)     在weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:884)     在weblogic.application.internal.ExtensibleModuleWrapper $ StartStateChange.next(ExtensibleModuleWrapper.java:360)     在weblogic.application.internal.ExtensibleModuleWrapper $ StartStateChange.next(ExtensibleModuleWrapper.java:356)     在weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)     在weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)     在weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)     在weblogic.application.internal.flow.ModuleStateDriver $ 3.next(ModuleStateDriver.java:233)     在weblogic.application.internal.flow.ModuleStateDriver $ 3.next(ModuleStateDriver.java:228)     在weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)     在weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:78)     在weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:52)     在weblogic.application.internal.BaseDeployment $ 2.next(BaseDeployment.java:752)     在weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)     在weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:262)     在weblogic.application.internal.EarDeployment.activate(EarDeployment.java:66)     在weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)     在weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:90)     在weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:274)     在weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:507)     在weblogic.management.deploy.internal.DeploymentAdapter $ 1.doActivate(DeploymentAdapter.java:53)     在weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:202)     在weblogic.management.deploy.internal.AppTransition $ 2.transitionApp(AppTransition.java:52)     在weblogic.management.deploy.internal.ConfiguredDeployments $ 2.doItem(ConfiguredDeployments.java:741)     在weblogic.management.deploy.internal.parallel.BucketInvoker.invoke(BucketInvoker.java:138)     在weblogic.management.deploy.internal.ConfiguredDeployments.transitionAppsParallel(ConfiguredDeployments.java:749)上     在weblogic.management.deploy.internal.ConfiguredDeployments.transitionAppsParallel(ConfiguredDeployments.java:702)     在weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:381)     在weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:233)     在weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:219)     在weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:133)     在weblogic.server.AbstractServerService.postConstruct(AbstractServerService.java:76)     在sun.reflect.GeneratedMethodAccessor5.invoke(未知来源)     在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)     在org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(ReflectionHelper.java:1287)     在org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:333)     在org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:375)     在org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487)     在org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:305)     在org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:85)     在org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126)     在org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:116)     在org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:698)     在org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:78)     在org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:212)     在org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:235)     在org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:358)     在org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487)     在org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:305)     在org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:85)     在org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126)     在org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:116)     在org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:90)     在org.glassfish.hk2.runlevel.internal.CurrentTaskFuture $ QueueRunner.oneJob(CurrentTaskFuture.java:1237)     在org.glassfish.hk2.runlevel.internal.CurrentTaskFuture $ QueueRunner.run(CurrentTaskFuture.java:1168)     在weblogic.work.SelfTuningWorkManagerImpl $ WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:670)     在weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)     在weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)     在weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)     在weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)     在weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:644)     在weblogic.work.ExecuteThread.execute(ExecuteThread.java:415)     在weblogic.work.ExecuteThread.run(ExecuteThread.java:355)

完整日志here

我试图添加这个

<init-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>

然后是

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>

web.xml ,但没有帮助

编辑

我将servlet重命名为DispatcherServlet,并将 dispatcher-servlet.xml 重命名为 DispatcherServlet-servlet.xml ,但是错误stil表示Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]

编辑2

我创建了一个新的干净的Spring MVC项目,问题仍然存在。我认为问题可能出在Weblogic中,我将尝试重新安装

2 个答案:

答案 0 :(得分:0)

尝试添加以下参数:

即:

<div class="container">
  <div class="in">Inside</div>
  <div class="in">
  Inside
  </div>
</div>

如果Servlet被称为DispatcherServlet,则根据Spring定义,xml必须被称为DispatcherServlet-servlet.xml

答案 1 :(得分:-1)

因此,问题出在Weblogic。我重新安装它,问题消失了