JavaShuo
栏目
标签
ssh框架整合
时间 2019-12-08
标签
ssh
框架
整合
繁體版
原文
原文链接
1.web.xml配置 ```xml
复制代码
OpenSessionInViewFilter
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
OpenSessionInViewFilter
*.action
struts2
*.jsp
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
*.action
contextConfigLocation
classpath:spring.xml
org.springframework.web.context.ContextLoaderListener
``` 2.导入所须要的jar包 ```java Struts 2: 1.commons-fileupload.jar(commons项目中的关于文件上传的包, struts2.1.6版本后必须加入此文件)
2.commons-io.jar(commons项目(commons项目就是java中一些经常使用的公共的组件)的io子项目,是处理异常的)
3.common-annotations.jar(支持注解的包)
4.aspectjrt.jar(支持AOP的包)
5.aspectjweaver.jar(支持AOP的包)
6.cglib-nodep-2.1_3.jar(支持cglib动态代理的包) 若是用BasicDataSource来配置数据库链接,还要加入2个包:
7.commons-pool.jar 8.commons-dbcp.jar hibernate 包: 1.hibernate3.jar(hibernate的核心jar包) 2.antlr-2.7.2.jar(语言转换工具,hibernate利用它实现HQL到SQL的转换) 3.commons-collections-3.2.1.jar(commons项目中的子项目,是对collection集合的封装) 4.dom4j-1.6.1.jar(对dom4j的封装,是解析xml文件的) 5.javassist-3.9.0.GA.jar(一个开源的分析、编辑和建立Java字节码的类库) 6.jta-1.1.jar(hibernate对事务的处理) 7.slf4j-api-1.6.4.jar(一个日志系统的服务的api) 8.slf4j-nop-1.6.4.jar(对slf4j-api-x.x.x.jar的一个实现) 9.ojdbc14.jar (oracle驱动) 10.mysql-connector-java-5.1.6-bin.jar (mySql驱动) 若是使用注解还需添加hibernate-annotations-3.4.0.GA包: 11.hibernate-annotations.jar 12.ejb3-persistence.jar 13.hibernate-commons-annotations.jar json须要的jar包: 1.commons-beanutils-1.8.2.jar 2.commons-collections-3.2.1.jar 3.commons-lang-2.5.jar 4.commons-logging-1.1.1.jar 5.ezmorph-1.0.6.jar 6.json-lib-2.2.3-jdk15.jar 另: EL表达式:jstl.jar excel表格:jxl.jar 操做pdf文件:iText-5.0.5.jar 统计图(JFreechart两个):jcommon-1.0.10.jar,jfreechart-1.0.6.jar ``` 3.搭建三层架构 ```java 1.bean类 注解: @Entity @Table(name="对应的表名") 字段上加对应的注解 @Id(主键) @GeneratedValue(strategy=GenerationType.AUTO)(代表自增加) 也能够写明对应的关系,如一对一,一对多 ``` ```java 2.action层 注解:@Controller(标明action层) @ParentPackage("struts-default")(继承的包,也能够是json-default) @Scope("protorype")(多例) @Namespace("/")(命名空间) 写入service类,在service类名上加上注解 @Resource 注入,写set,get方法 在方法上加上注解 @Action(value = "方法名", results = { @Result(name = "success", location = "/main.jsp"), @Result(name = "input", location = "/login.jsp") }) ``` ```java 3.service实现层 注解:@Service 写入dao类,在dao类名上加上注解 @Resource 注入,写set,get方法 ``` ```java 4.dao实现层 注解:@Repository 加入 @Autowired private JdbcTemplate jdbcTemplate; 不须要写set,get方法,能够直接用jdbcTemplate调方法 ``` 4.建立文件jdbc.properties,spring.xml ```xml jdbc.properties: ## jdbc 链接配置 jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://loaclhost:3306/spring-good jdbc.user=root jdbc.password=root ## c3p0 数据源配置 c3p0.minPoolSize=15 c3p0.maxPoolSize=25 c3p0.acquireIncrement=15 c3p0.checkoutTimeout=10000 c3p0.initialPoolSize=20 c3p0.maxIdleTime=20 c3p0.idleConnectionTestPeriod=60000 spring.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:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd"> <!-- 自动扫描包下的文件 --> <context:component-scan base-package="com.znsd.ssh"/> <!-- 经过context:property-placeholder加载配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置c3p0链接池属性 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring-good" /> <property name="user" value="${jdbc.user}" /> <property name="password" value="${jdbc.password}" /> <!-- 队列中的最小链接数 --> <property name="minPoolSize" value="${c3p0.minPoolSize}"></property> <!-- 队列中的最大链接数 --> <property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property> <!-- 当链接耗尽时建立的链接数 --> <property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property> <!-- 等待时间 --> <property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"></property> <!-- 初始化链接数 --> <property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property> <!-- 最大空闲时间,超出时间链接将被丢弃 --> <property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property> <!-- 每隔60秒检测空闲链接 --> <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"></property> </bean> <!-- session工厂由spring来管理 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <!-- 数据源配置 --> <property name="dataSource" ref="dataSource"></property> <!-- 读取hibernate配置信息 --> <!-- <property name="configLocation" value="classpath:hibernate.cfg.xml" /> --> <!-- 自动加载映射文件 *表示匹配该文件下的全部映射文件 --> <property name="packagesToScan"> <list> <value>com.znsd.ssh.bean</value> </list> </property> <!--各类hibernate属性 --> <property name="hibernateProperties"> <props> <!-- 方言 --> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <!-- <prop key="hibernate.current_session_context_class">thread</prop> --> <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext </prop> </props> </property> </bean> <!-- 数据源的注入 --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置事务 --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- AOP切面拦截事务 --> <aop:config> <aop:pointcut id="serviceMethod" expression="execution(* com.znsd.ssh.service.impl.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" /> </aop:config> <!-- 事务的通知方式 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- read-only 事务为只读,通常查询数据可把该属性设置为true,能够提高效率 --> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="search*" propagation="REQUIRED" read-only="true" /> <tx:method name="query*" propagation="REQUIRED" read-only="true" /> <!-- propagation为事务的传播属性,经常使用为REQUIRED:若是当前线程有事务就直接使用当前事务,没有就建立一个事务 --> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="submit*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> </beans> ```
不知道怎么回事。。。
相关文章
1.
SSH框架整合
2.
SSH整合框架
3.
ssh框架整合
4.
SSH 框架整合
5.
SSH框架整合一
6.
SSH框架整合总结
7.
SSH三大框架整合
8.
idea整合SSH框架
9.
SSH框架整合案例
10.
ssh框架整合意义
更多相关文章...
•
SSH框架(Struts2+Spring+Hibernate)搭建整合详细步骤
-
Spring教程
•
测试SSH框架分层整合及验证事务是否有效
-
Spring教程
•
适用于PHP初学者的学习线路和建议
•
常用的分布式事务解决方案
相关标签/搜索
SSH框架
集合框架
框架融合
企业级框架整合
SSH三大框架
SSH框架搭建
框架
整合
JAVA集合框架
ssh
Spring教程
Hibernate教程
MyBatis教程
架构
0
分享到微博
分享到微信
分享到QQ
每日一句
每一个你不满意的现在,都有一个你没有努力的曾经。
最新文章
1.
子类对象实例化全过程
2.
【Unity2DMobileGame_PirateBomb09】—— 设置基本敌人
3.
SSIS安装以及安装好找不到商业智能各种坑
4.
关于 win10 安装好的字体为什么不能用 WebStrom找不到自己的字体 IDE找不到自己字体 vs找不到自己字体 等问题
5.
2019版本mac电脑pr安装教程
6.
使用JacpFX和JavaFX2构建富客户端
7.
MySQL用户管理
8.
Unity区域光(Area Light) 看不见光线
9.
Java对象定位
10.
2019-9-2-用自动机的思想说明光速
本站公众号
欢迎关注本站公众号,获取更多信息
相关文章
1.
SSH框架整合
2.
SSH整合框架
3.
ssh框架整合
4.
SSH 框架整合
5.
SSH框架整合一
6.
SSH框架整合总结
7.
SSH三大框架整合
8.
idea整合SSH框架
9.
SSH框架整合案例
10.
ssh框架整合意义
>>更多相关文章<<