SpringMVC + Weblogic部署疑问


最近研究SpringMVC的时候,在部署项目的时候,一开始是用tomcat去部署的,可以访问到项目的文件,后来我又尝试在weblogic部署,发现无法访问项目。weblogic服务器可以正常启动,也能进入控制台,就是无法访问自己的项目文件,通过启动的控制台信息,发现SpringMVC的配置文件没有被加载解析,
web.xml 文件配置信息


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

    <!-- springMVC 核心控制器 -->
    <servlet>
        <servlet-name>springMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <!-- 自定义加载xml文件,而不是默认的[servlet-name]-servlet.xml -->
            <param-value>classpath:/META-INF/springMVC.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!--
        一旦DispatcherServlet的初始化, 它会查找一个文件名[servlet-name]-servlet.xml
        Web应用程序的WEB-INF文件夹中
    -->
    <servlet-mapping>
        <servlet-name>springMVC</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <!-- 解决中文乱码问题,使用Spring3.0自带的过滤器 -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

weblogic.xml


 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
<weblogic-web-app>
    <container-descriptor>
        <single-threaded-servlet-pool-size>50</single-threaded-servlet-pool-size>
    </container-descriptor>
    <context-root>/</context-root>
</weblogic-web-app>

springMVC.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:tx="http://www.springframework.org/schema/tx"
    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-3.0.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.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-3.0.xsd">


    <!-- 自动扫描包,可以写多个 -->
    <context:component-scan base-package="com.study" ></context:component-scan>

    <!-- 多视图处理器 -->
    <bean class="com.study.viewResolver.MixedViewResolver">
        <property name="resolvers">
            <map>
                <entry key="jsp">
                    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
                        <property name="contentType" value="text/html" />
                        <property name="prefix" value="/WEB-INF/views/"/>
                        <!--可以不填,自定义,比如 xxx.html-->
                        <!--<property name="suffix" value=".jsp"></property>-->
                    </bean>
                </entry>
            </map>
        </property>
    </bean>

    <!-- 总错误处理-->
    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">

        <property name="exceptionMappings"> 
            <props> 
            <!-- 上传文件大于最大尺寸后转向出错页面 --> 
                <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException"> 
                    redirect:/uploadError.jsp
                </prop> 
            </props> 
        </property> 
        <property name="defaultErrorView">  
            <value>forward:/error.jsp</value>
        </property>
        <property name="defaultStatusCode">  
            <value>200</value>
        </property>         
        <property name="warnLogCategory">  
            <value>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver</value>
        </property>         

    </bean> 

    <!-- 允许对静态资源文件的访问 --> 
    <!--<mvc:default-servlet-handler/>-->
    <!-- 配置js,css等静态文件直接映射到对应的文件夹,不被DispatcherServlet处理 -->
    <!-- 对静态资源文件的访问  方案一 (二选一) -->
    <mvc:resources location="/resources/bootstrap/" mapping="/bootstrap/**"
        cache-period="31556926" />
    <mvc:resources location="/resources/css/" mapping="/css/**" />
    <mvc:resources location="/resources/js/" mapping="/js/**" />
    <mvc:resources location="/resources/imgs/" mapping="/images/**" />

    <!-- 数据源 ,DBCP连接池-->
    <!-- JNDI数据源 -->
    <bean id="dataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="ZQBTEST" />
        <property name="jndiEnvironment">
            <props>
                <prop key="java.naming.factory.initial">
                    weblogic.jndi.WLInitialContextFactory
                </prop>
                <prop key="java.naming.provider.url">
                    t3://127.0.0.1:18088
                </prop>
                <prop key="java.naming.factory.url.pkgs">
                    weblogic.jndi.factories
                </prop>
                <prop key="java.naming.security.principal">
                    weblogic
                </prop>
                <prop key="java.naming.security.credentials">
                    weblogic
                </prop>
            </props>
        </property>
    </bean>



    <!-- JDBC模板 -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 用注解来实现事务管理 -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

    <!-- 用于持有ApplicationContext,可以使用SpringContextHolder.getBean('xxxx')的静态方法得到spring bean对象 -->  
    <bean class="com.study.controller.SpringContextHolder" lazy-init="false" />  

</beans>

java 框架

van酱. 10 years, 6 months ago

Your Answer