<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> |
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate> <property name="sessionFactory" ref="sessionFactory"></property> </bean> |
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value><!--这个是默认的--> <param-value>classpath:beans.xml</param-value> </context-param> |
<filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <!—这个filter默认找的是名字为sessionFactory的session工厂--> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sf</param-value> <!—指定新的名字--> </init-param> </filter> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
<filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter.class</filter-class> <init-param> <param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> </filter> <filter-mapping> <fiter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> <filter-mapping> |
<?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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context[/url] http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName"> <!--default-autowire="byName" 定义注入依赖通过 对象名称--> <!--Spring2.5中基于注释的依赖注入--> <context:annotation-config/> <!-- 事务配置,注册Spring实现的为hiberante而写的 HibernateTransactionManager--> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 使用annotation定义事务,事务管理者为前面定义HibernateTransactionManager,并且对目标类生成代理--> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <!-- 使用annotation 自动注册bean,从指定的包下 --> <context:component-scan base-package="cn.com" /> <!--指定数据源--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.OracleDriver"> </property> <property name="url" value="jdbc:oracle:thin:@guest753:1521:accp"> </property> <property name="username" value="scott"></property> <property name="password" value="tiger"></property> </bean> <!--注册sessionFactory--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9iDialect </prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <!--定义扫描那些包下的类作为entity实体对象管理--> <property name="packagesToScan"> <list> <value>cn.com.entity.*</value> </list> </property> </bean> </beans> |
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee [url]http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Stu</display-name> <!-- struts2支持 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>actionsPackages</param-name> <param-value>cn.com.action</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 添加监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app> |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |