MyEclipse8.5搭建ssh2框架
建一个web工程
工程中右键点击添加struts支持,》》》在选择Struts2.1,选择/*》》》选择core核心包
工程中右键点击添加spring支持,》》》在选择1,spring 3.0 aop libraries
2,spring 3.0 core libraries
3,spring 3.0 persistence core libraries
4,spring 3.0 persistence jdbc liberaries
5,spring 3.0 web libraries
最后添加hibernate支持:只选Hibernate 3.3 core libraries》》》再选springconfiguation file
使用spring配置文件》》》》在选择Existing spring configuration file 已经存在的spring配置文件》》》到最后去掉勾选 create sessionfactory class 不用再创建sessionfactory了。
5在src目录下建一个dto的包
选择dbBrowser视图,选中要创建的表,右键选中hibernate reverse engineering
在选中dto目录
Create pojo<>db table mapping information勾选
Java data object(pojo……勾选 createabstract class 不用选
Java data Access object……. 勾选,generateprecise findBy method….勾选
Next》》》》className:dto.MapDto
IdGenerator :sequence
Web.xml添加:
<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>
Applicationcontext.xml添加
<?xml version="1.0"encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource">
<propertyname="driverClassName"value="oracle.jdbc.driver.OracleDriver"></property>
<propertyname="url"value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<propertyname="username" value="zhou"></property>
<propertyname="password" value="z1234"></property>
</bean>
<beanid="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<propertyname="dataSource"><ref bean="dataSource"/></property>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<propertyname="mappingResources">
<list>
<value>dto/MapDto.hbm.xml</value></list>
</property></bean>
<bean id="mytx"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"ref="sessionFactory"></property>
</bean>
<beanid="MapDtoDAO" class="dao.MapDtoDAOImpl">
<propertyname="sessionFactory"><ref bean="sessionFactory"/>
</property>
</bean>
<tx:advice id="myadvice"transaction-manager="mytx">
<tx:attributes>
<tx:method name="add*"propagation="REQUIRED"/>
<tx:method name="modify*"propagation="REQUIRED"/>
<tx:method name="del*"propagation="REQUIRED"/>
<tx:method name="*"propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(*biz.*.*(..))" id="mypoint"/>
<aop:advisor advice-ref="myadvice"pointcut-ref="mypoint"/>
</aop:config>
</beans>
写好业务层,和dao层
启动tomcat报错
因为少了一个包 struts2-spring-plugin-2.1.8.1
添加进去就可以了。