<?xml version="1.0" encoding="GBK"?>
<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"> <!-- 配置Spring配置文件的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>applicationContext.xml</param-value>
</context-param>
<!-- 使用ContextLoaderListener初始化Spring容器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 定义Struts 2的核心Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- 让Struts 2的核心Filter拦截所有请求 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
项目本来是用hibernate和struts2完成的,做完以后,我尝试着用spring整合起来。。可是web.xml一加入context-param子元素和ContextLoaderListener监听器,就没办法访问网站了,一直404错误

解决方案 »

  1.   

    <?xml version="1.0" encoding="GBK"?>
    <!-- 指定Spring配置文件的Schema信息 -->
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- 定义数据源Bean,使用C3P0数据源实现 -->
    <!-- 设置连接数据库的驱动、URL、用户名、密码
    连接池最大连接数、最小连接数、初始连接数等参数 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"
    p:driverClass="com.mysql.jdbc.Driver"
    p:jdbcUrl="jdbc:mysql://localhost:3306/hibernate"
    p:user="root"
    p:password="32147"
    p:maxPoolSize="40"
    p:minPoolSize="1"
    p:initialPoolSize="1"
    p:maxIdleTime="20"/> <!-- 定义Hibernate的SessionFactory -->
    <!-- 依赖注入数据源,注入正是上面定义的dataSource -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource">
    <!-- mappingResouces属性用来列出全部映射文件 -->
    <property name="mappingResources">
    <list>
    <!-- 以下用来列出Hibernate映射文件 -->
    <value>org/crazyit/hrsystem/domain/Application.hbm.xml</value>
    <value>org/crazyit/hrsystem/domain/Attend.hbm.xml</value>
    <value>org/crazyit/hrsystem/domain/AttendType.hbm.xml</value>
    <value>org/crazyit/hrsystem/domain/CheckBack.hbm.xml</value>
    <value>org/crazyit/hrsystem/domain/Employee.hbm.xml</value>
    <value>org/crazyit/hrsystem/domain/Payment.hbm.xml</value>
    </list>
    </property>
    <!-- 定义Hibernate的SessionFactory的属性 -->
    <property name="hibernateProperties">
    <!-- 指定数据库方言、是否自动建表
    是否生成SQL语句等  -->
    <value>
    hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
    hibernate.hbm2ddl.auto=update
    hibernate.show_sql=true
    hibernate.format_sql=true
    #开启二级缓存
    hibernate.cache.use_second_level_cache=true
    #设置二级缓存的提供者
    hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
    </value>
    </property>
    </bean>
    </beans>
    这是applicationContext.xml的内容,求大侠帮我看看
      

  2.   

    我用的是tomcat没办法截取,查了半天,只看到说在配置sessionFactory的时候,没有找到Application.hbm.xml。
      

  3.   

    你的 SPRING配置上出了错误!还想还能加个什么忘了!!去网上看下配置文件吧
      

  4.   

    你用的是Tomcat,启动的时候也有信息打印出来啊!!服务器启动应该有错,可能是漏加jar包了
      

  5.   

    <!-- 配置Spring配置文件的位置 -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>applicationContext.xml</param-value> 改成 classpath*:applicationContext.xml 试试
    </context-param>
    <!-- 使用ContextLoaderListener初始化Spring容器 -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
      

  6.   

    tomcat也会有错误信息啊,不管服务器的事