現(xiàn)在很多公司在開發(fā)項(xiàng)目的時(shí)候都在使用ssh進(jìn)行搭建環(huán)境,那么ssh項(xiàng)目環(huán)境搭建的五個(gè)步驟大家了解嗎?別著急,下面就讓錯(cuò)新技術(shù)頻道小編為大家詳解這些步驟吧。
一、創(chuàng)建Web項(xiàng)目
二、加入Struts2支持(Struts-2.3.1.2版本)
1、?? 拷貝相關(guān)jar包到lib目錄下
(1)????? struts2-core-2.3.1.2.jar
(2)????? xwork-core-2.3.1.2.jar
(3)????? ognl-3.0.4.jar
(4)????? freemarker-2.3.18.jar
(5)????? commons-logging-1.1.1.jar
(6)????? commons-io-2.0.1.jar
(7)????? commons-lang-2.5.jar
(8)????? commons-fileupload-1.2.2.jar
(9)????? javassist-3.11.0.GA.jar
(10)? struts2-spring-plugin-2.3.1.2.jar(整合Spring)
2、?? 配置web.xml文件
(1)????? 打開struts-2.3.1.2/apps/struts2-blank.war文件,查看其中web.xml配置
(2)????? 拷貝相關(guān)內(nèi)容如下:
?
3、拷貝struts-2.3.1.2/apps/struts2-blank.war中的struts.xml文件到src下,大致內(nèi)容如下:
?
4、增加相關(guān)的Xxx.hbm.xml文件到相應(yīng)的包下面,內(nèi)容大致如下:
?
三、增加Spring支持(Spring-framework-2.5.6版本)
1、拷貝相關(guān)jar包到lib目錄下
(1)spring.jar
(2)aspectjweaver.jar
2、在spring-framework-2.5.6/samples目錄下拷貝applicationContext.xml到src目錄下面,并修改文件名為applicationContext-common.xml,大致內(nèi)容如下
?
3、修改web.xml配置文件,增加內(nèi)容如下:
[coe]
<!--增加監(jiān)聽,負(fù)責(zé)加載Spring文件-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--指定Spring的相關(guān)配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
[/code]
四、增加Hibernate支持(Hibernate-distribution-3.6.10.Final)
1、拷貝相關(guān)包到lib下,包括hibernate-distribution-3.6.10.Final/lib/required文件夾下相關(guān)jar文件,jar如下列表:
(1)hibernate3.jar
(2)antlr-2.7.6.jar
(3)commons-collections-3.1.jar
(4)dom4j-1.6.1.jar
(5)jta-1.1.jar
(6)slf4j-api-1.6.1.jar
(7)hibernate-jpa-2.0-api-1.0.1.Final.jar
2、拷貝數(shù)據(jù)庫(kù)相關(guān)的jar文件到lib下,如:mysql-connector-java-5.1.18-bin.jar
五、整合Hibernate和Spring
1、修改applicationContext-common.xml文件,增加內(nèi)容如下:
?
<!--2.配置SessionFactory-->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--注入DataSource-->
<propertyname="dataSource"ref="dataSource"/>
<!--映射文件列表-->
<propertyname="mappingResources">
<list>
<value>com/oracle/po/Customer.hbm.xml</value>
</list>
</property>
<!--Hibernate相關(guān)屬性配置-->
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<!--3.定義事務(wù)管理器-->
<beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"/>
</bean>
<!--4.配置Spring對(duì)Hibernate的事務(wù)管理的傳播特性-->
<tx:adviceid="txAdvice"transaction-manager="transactionManager">
<tx:attributes>
<tx:methodname="add*"propagation="REQUIRED"/>
<tx:methodname="modify*"propagation="REQUIRED"/>
<tx:methodname="del*"propagation="REQUIRED"/>
<tx:methodname="*"read-only="true"/>
</tx:attributes>
</tx:advice>
<!--5.配置Spring對(duì)Hibernate事務(wù)的切入點(diǎn)-->
<aop:config>
<aop:pointcutexpression="execution(*com.oracle.dao.*.*(..))"id="allManagerMethod"/>
<aop:advisoradvice-ref="txAdvice"pointcut-ref="allManagerMethod"/>
</aop:config>
以上就是關(guān)于ssh項(xiàng)目環(huán)境搭建的五個(gè)步驟的全部介紹,相信這些內(nèi)容一定對(duì)你是很有用的,小編為大家推薦錯(cuò)新技術(shù)頻道給你學(xué)習(xí)。
新聞熱點(diǎn)
疑難解答
圖片精選