复用代码【SSH配置文件】
2018-01-21 00:00
337 查看
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_3_1.xsd" version="3.1"> <!-- 配置spring的OpenSessionInView模式 【目的:JSp页面访问懒加载数据】 --> <!-- 注意:访问struts时候需要带上*.action后缀 --> <filter> <filter-name>OpenSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInView</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <!--初始化Struts功能--> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--初始化Spring容器--> <!-- 2. spring 配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/bean-*</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
bean-base.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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 1) 连接池实例 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql:///zhongfucheng?characterEncoding=utf8"></property> <property name="user" value="root"></property> <property name="password" value="root"></property> <property name="initialPoolSize" value="3"></property> <property name="maxPoolSize" value="6"></property> </bean> <!-- 2) SessionFactory实例创建 --> <!-- 所有的配置都由spring维护(项目中不需要hibernate.cfg.xml啦) --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- a. 连接池 --> <property name="dataSource" ref="dataSource"></property> <!-- b. hibernate常用配置: 方言、显示sql、自动建表等 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <!-- c. 映射配置 --> <property name="mappingLocations"> <list> <value>classpath:zhongfucheng/entity/*.hbm.xml</value> </list> </property> </bean> <!-- 3) 事务配置 --> <!-- # 事务管理器 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- # 事务增强 --> <!-- <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="*" read-only="false"/> </tx:attributes> </tx:advice> <!– # AOP配置 –> <aop:config> <aop:pointcut expression="execution(* cn.itcast.service.*.*(..))" id="pt"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/> </aop:config>--> <!--4)开启注解扫描器--> <context:component-scan base-package="zhongfucheng"/> <!--5)开启注解处理事务--> <tx:annotation-driven transaction-manager="txManager"/> </beans>
Struts2.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="aaa" extends="struts-default"> <action name="ccc" class="userAction" method="execute"> <result name="success">/show.jsp</result> </action> </package> </struts>
映射文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="zhongfucheng.entity"> <class name="Dept" table="t_dept"> <id name="id" > <generator class="native"></generator> </id> <property name="name" column="name"></property> </class> </hibernate-mapping>
相关文章推荐
- 复用代码【SSH配置文件】
- ssh三大框架整合配置文件及测试代码
- eShop电子商城的SSH实现的用户模块(1)登录和注册配置文件和页面关键代码(V...
- ssh整合时各个配置文件需要修改添加的代码
- Struts2配置文件复用代码【web.xml、struts.xml、常量配置】
- 数据库复用代码【c3p0配置文件、数据库连接池】
- 数据库复用代码【c3p0配置文件、数据库连接池】
- Struts2配置文件复用代码【web.xml、struts.xml、常量配置】
- JAVA代码读取配置文件信息 *.properties
- Nginx的启动、停止与重启 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx
- FPGA配置文件和NIOS代码程序写入EPCS
- log4j配置文件ssh整合(二)参考
- Linux下配置文件读取操作流程及其C代码实现
- Myeclipse2015 Jrebel插件的安装、配置、使用(新建.java文件、给类添加新方法、新属性、修改代码等,不用重启tomcat即可更新)
- spring3支持@value注解从配置文件中读取配置值,大大简化读取配置文件的代码@
- JSP中数据源的绑定方法(Resin配置文件中和代码动态配置的方法)
- ssh配置文件
- zf-关于评价器的开关所在的配置文件,与代码如何修改。
- java代码里获取xml文件里的数据库配置信息
- 利用 ssh 的用户配置文件 config 管理 ssh 会话