简单搭建注解ssh项目(一)
2017-01-07 11:12
323 查看
1.使用的IDE:Myeclipse2013
2.使用数据库:mysql
3.使用hibernate:hibernate4.1.4,spring:spring3.1,struts2:struts2-2.3.16
4.jdk1.6 tomcat6
OK,环境准备好之后就可进行框架搭建了
1.在myeclipse中新建一个web项目
2.添加框架支持(为了不用写xml配置文件,一会儿就删掉),分别添加spring,hibernate,struts2,版本就用自带最新的即可
2-1:添加spring框架:下一步下一步即可
2-2:添加hibernate框架之前我们先添加数据源的配置,以后就不需要再次配置了。
1.切换一个工作台到hibernate
2.创建数据源
3.我们使用mysql,保存密码
4.点击Test Driver,如果出现以下内容表示连接成功
5.下一步直到结束为止。
2-3:添加hibernate框架:注意如图
1.不需要SessionFactory Class.因为我们将SessionFactory交给Spring管理
2.选择刚刚创建的数据源,下一步到结束为止
2-4:添加Struts2的框架支持:下一步即可:注意如图,将核心控制器的过滤规则改为/*
3.添加完框架支持之后,将三个框架的支持在remove掉(右击builder path:remove掉即可),删除之后就是这个样子
4.添加项目所需要的jar包:
sshjar包下载地址
还缺少三个包:下载地址(一定要加入这三个jar包。struts注解使用)
5.编辑spring的配置文件
5-1.导入context命名空间
5-2.开启注解自动扫描:会扫描com.yy包下所有包中所有带注解的类。在spring中将这些类管理起来
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 这一段就不需要了 -->
<!-- <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property> -->
<!-- 实体类自动扫面装配 -->
<property name="packagesToScan" value="com.yy.po">
</property>
</bean>5-4.配置声明式事务
2.使用数据库:mysql
3.使用hibernate:hibernate4.1.4,spring:spring3.1,struts2:struts2-2.3.16
4.jdk1.6 tomcat6
OK,环境准备好之后就可进行框架搭建了
1.在myeclipse中新建一个web项目
2.添加框架支持(为了不用写xml配置文件,一会儿就删掉),分别添加spring,hibernate,struts2,版本就用自带最新的即可
2-1:添加spring框架:下一步下一步即可
2-2:添加hibernate框架之前我们先添加数据源的配置,以后就不需要再次配置了。
1.切换一个工作台到hibernate
2.创建数据源
3.我们使用mysql,保存密码
4.点击Test Driver,如果出现以下内容表示连接成功
5.下一步直到结束为止。
2-3:添加hibernate框架:注意如图
1.不需要SessionFactory Class.因为我们将SessionFactory交给Spring管理
2.选择刚刚创建的数据源,下一步到结束为止
2-4:添加Struts2的框架支持:下一步即可:注意如图,将核心控制器的过滤规则改为/*
3.添加完框架支持之后,将三个框架的支持在remove掉(右击builder path:remove掉即可),删除之后就是这个样子
4.添加项目所需要的jar包:
sshjar包下载地址
还缺少三个包:下载地址(一定要加入这三个jar包。struts注解使用)
5.编辑spring的配置文件
5-1.导入context命名空间
5-2.开启注解自动扫描:会扫描com.yy包下所有包中所有带注解的类。在spring中将这些类管理起来
<context:component-scan base-package="com.yy"></context:component-scan>5-3.开启持久化类的自动装配:<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 这一段就不需要了 -->
<!-- <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property> -->
<!-- 实体类自动扫面装配 -->
<property name="packagesToScan" value="com.yy.po">
</property>
</bean>5-4.配置声明式事务
<!-- 配置声明式事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 导入tx命名空间 --> <tx:annotation-driven transaction-manager="transactionManager"/>5-5.spring配置文件的内容目前:
<?xml version="1.0" encoding="UTF-8"?>6.struts2的配置文件内容:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/company">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 这一段就不需要了 -->
<!-- <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property> -->
<!-- 实体类自动扫面装配 -->
<property name="packagesToScan" value="com.yy.po">
</property>
</bean>
<!-- 开启注解自动扫描 -->
<context:component-scan base-package="com.yy"></context:component-scan>
<!-- 配置声明式事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 导入tx命名空间 --> <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
<struts> <!-- 将spring的action创建交给spring管理 --> <constant name="struts.objectFactory" value="spring"></constant> <!-- 开启动态方法调用 --> <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant> </struts>
相关文章推荐
- 简单搭建注解ssh项目(二)
- 搭建基于注解方式的SSH项目框架
- 简单ssh注解模式搭建
- 【SSH 框架项目的搭建--简化版】使用注解代替xml中的<bean>,减少代码量
- ssh项目使用注解搭建
- 如何搭建ssh项目(基于注解)
- eclipse搭建一个简单的SSH项目
- 搭建基于注解方式的SSH项目框架
- 85-002 商城项目前期简单搭建【上】(SSH+EasyUI+ajax+jquery+tomcat)
- 使用注解,实现ssh项目中spring配置文件的零配置,约定优于配置
- 学习之路--项目整体框架简单的搭建
- Maven搭建简单的SS项目
- 学习之路--项目整体框架简单的搭建
- asp.net 学习之路 项目整体框架简单的搭建
- tomcat下搭建简单的xfire web services项目
- Maven4MyEclipse 搭建ssh2+extjs项目(1)创建mavenweb项目
- OA中总结:s:select,关于使用modelDriven,项目分层,@Transactional,jspf,各个层上配置注解交给spring管理的方法,简单的OGNL表达式写法
- XP下简单maven项目搭建(不含maven如何安装)
- Mondrian用于web项目的一个简单搭建实验
- 从零搭建SSH项目之Hibernate3.3项目