myeclispe_搭建SSH2 简单步骤

1.spring hibernate 搭建跟ssh1一样

2.加入struts2.所必须的jar包及struts2 plugin for spring 2.1.11

3.在web。xml中加入以下代码........

web.xml 代码如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	
	   <!-- struts2的常规配置 -->  
    <filter>  
        <filter-name>struts2</filter-name>  
        <filter-class>  
            org.apache.struts2.dispatcher.FilterDispatcher   
        </filter-class>  
    </filter>  
    <filter-mapping>  
        <filter-name>struts2</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
     <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value>  
    </context-param> 
       
        <!-- sping监听 -->  
    <listener>    
        <listener-class>  
            org.springframework.web.context.ContextLoaderListener   
        </listener-class>  
    </listener>  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
  
</web-app>

 

3.新建struts.xml 放入class目录下 实例代码如下

 

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE struts PUBLIC   
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
    "http://struts.apache.org/dtds/struts-2.0.dtd">  
       
    <struts>  
     
        <package name="default" extends="struts-default">    
       
        <action name="saveUser" class="UserAction">   
            <result name="success" type="redirect">/2.jsp</result>  
            <result name="input">/saveUser.jsp</result>  
        </action> 
       
    </package>  
    
    </struts>  
    

 

4.新建struts.proprites 文件 加入

struts.objectFactory=spring 

 

5.spring 注入 applicationContext.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:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
 	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
 	http://www.springframework.org/schema/tx 
  	http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
	http://www.springframework.org/schema/aop 
  	http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
  	
	<bean id="DataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName"
			value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
		</property>
		<property name="url"
			value="jdbc:sqlserver://127.0.0.1:1433;databaseName=DBuser">
		</property>
		<property name="username" value="alei"></property>
		<property name="password" value="123"></property>
	</bean>
	
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="DataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.SQLServerDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop> 
			</props>
			
		</property>
		<property name="mappingResources">
			<list>
				<value>com/alei/dao/Users.hbm.xml</value>
			</list>
		</property>
		</bean>
	<bean id="UsersDAO" class="com.alei.dao.UsersDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<bean id="UserService" class="com.alei.service.UserService">
	 <property name="idao">
	 <ref bean="UsersDAO"></ref>
	 </property>
	 </bean>
	 
	 <bean name="UserAction" class="com.alei.action.UserAction">
	 <property name="iservice">
	    <ref bean="UserService"></ref>
	 </property>
	 
	 </bean>
	

	</beans>

 

  基本上就这几点 这只是简单的个demo 其它的功能还要自己完成

 

你可能感兴趣的:(spring,AOP,bean,Hibernate,struts)