`
txazo
  • 浏览: 79476 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Struts2.3.4.1 + Spring3.1.2 + Hibernate4.1.6整合

    博客分类:
  • SSH2
阅读更多
1. Jar包
2. web.xml配置
3. struts.xml配置
4. hibernate.cfg.xml配置
5. applicationContext.xml配置
6. log4j.properties配置
7. Dao层
8. Service层
9. Action层

1. Jar包
1) Struts 2.3.4.1
下载地址:http://struts.apache.org/download
/lib/commons-fileupload-1.2.2.jar
/lib/commons-io-2.0.1.jar
/lib/commons-lang3-3.1.jar
/lib/freemarker-2.3.19.jar
/lib/javassist-3.11.0.GA.jar
/lib/ognl-3.0.5.jar
/lib/struts2-core-2.3.4.1.jar
/lib/struts2-spring-plugin-2.3.4.1.jar
/lib/xwork-core-2.3.4.1.jar

2) Spring 3.1.2
下载地址:http://www.springsource.org/download
/dist/*

3) Hibernate 4.1.6
下载地址:http://sourceforge.net/projects/hibernate/files/hibernate4
/lib/required/*
/lib/envers/hibernate-envers-4.1.6.Final.jar
/lib/jpa/hibernate-entitymanager-4.1.6.Final.jar
/lib/optional/c3p0/c3p0-0.9.1.jar
/lib/optional/c3p0/hibernate-c3p0-4.1.6.Final.jar

4) Aopalliance 1.0
下载地址:http://sourceforge.net/projects/aopalliance
aopalliance.jar

5) Aspectj 1.7.0
下载地址:http://www.eclipse.org/aspectj/downloads.php
aspectjrt.jar
aspectjweaver.jar

6) Cglib 2.2.3
下载地址:http://sourceforge.net/projects/cglib/files
cglib-2.2.3.jar

7) Asm 3.3
下载地址:http://forge.ow2.org/projects/asm
asm-3.3.jar

8) Log4j 1.2.17
下载地址:http://logging.apache.org/log4j/1.2/download.html
log4j-1.2.17.jar

9) MySQL Connector Java 5.1.21
下载地址:http://dev.mysql.com/downloads/connector/j
mysql-connector-java-5.1.21-bin.jar

10)Commons Logging 1.1.1
下载地址:http://commons.apache.org/logging
commons-logging-1.1.1.jar

2. web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"     
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	version="3.0">

	<!-- Welcome File List -->
	<welcome-file-list>
		<welcome-file>login.html</welcome-file>
	</welcome-file-list>

	<!-- WebApp Root -->
	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>webapp.root</param-value>
	</context-param>

	<!-- Spring Encoding Filter -->
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>

	<!-- Spring Encoding Filter Mapping -->
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>


	<!-- Struts2 Filter -->
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
            org.apache.struts2.dispatcher.ng.filter.
                StrutsPrepareAndExecuteFilter
        </filter-class>
	</filter>

	<!-- Struts2 Filter Mapping -->
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- Log4j ConfigurationFile Location -->
	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>classpath:log4j.properties</param-value>
	</context-param>

	<!-- Spring Log4j Listener -->
	<listener>
		<listener-class>
            org.springframework.web.util.Log4jConfigListener
        </listener-class>
	</listener>

	<!-- Spring ConfigurationFile Location -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	<!-- Spring Context Listener -->
	<listener>
		<listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
	</listener>

	<!-- Spring Web Request Listener -->
	<listener>
		<listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
	</listener>

	<!-- Spring Introspector Cleanup Listener -->
	<listener>
		<listener-class>
            org.springframework.web.util.IntrospectorCleanupListener
        </listener-class>
	</listener>

</web-app>

3. struts.xml配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

	<constant name="struts.devMode" value="false" />
	<constant name="struts.i18n.encoding" value="UTF-8" />

	<package name="default" namespace="/" extends="struts-default">

		<action name="login" method="login" class="loginAction">
			<result name="input">/login.html</result>
			<result name="success">/home.jsp</result>
		</action>

	</package>

</struts>

4. hibernate.cfg.xml配置
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

	<session-factory>
		<property name="dialect">
            org.hibernate.dialect.MySQLDialect
        </property>

		<property name="show_sql">true</property>
		<property name="format_sql">true</property>
		<property name="hbm2ddl.auto">update</property>

		<mapping class="com.txazo.domain.User" />
	</session-factory>

</hibernate-configuration>

5. 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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
            http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
            http://www.springframework.org/schema/aop  
            http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
            http://www.springframework.org/schema/tx  
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
            http://www.springframework.org/schema/context  
            http://www.springframework.org/schema/context/
                spring-context-3.1.xsd">

	<!-- DataSource -->
	<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://127.0.0.1:3306/txazo" />
		<property name="user" value="root" />
		<property name="password" value="root" />
	</bean>

	<!-- SessionFactory -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
		p:dataSource-ref="dataSource"  
        p:configLocation="classpath:hibernate.cfg.xml" />

	<!-- TransactionManager -->
	<bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager"
        p:sessionFactory-ref="sessionFactory" />

	<!-- Spring Advice -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true"></tx:method>
			<tx:method name="*"></tx:method>
		</tx:attributes>
	</tx:advice>

	<!-- Spring Aop Config -->
	<aop:config>
		<aop:pointcut id="pointcut"
			expression="
                execution(* com.txazo.service.impl.*Impl.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
	</aop:config>

	<!-- Dao -->
	<bean id="baseDao" class="com.txazo.dao.impl.BaseDaoImpl">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>

	<!-- Service -->
	<bean id="userService" class="com.txazo.service.impl.UserServiceImpl">
		<property name="baseDao">
			<ref bean="baseDao" />
		</property>
	</bean>

	<!-- Action -->
	<bean id="loginAction" class="com.txazo.action.LoginAction"  
        scope="session">
		<property name="userService">
			<ref bean="userService" />
		</property>
	</bean>

</beans>

6. log4j.properties配置
# Set The RootLogger
log4j.rootLogger=warn, console

# Direct Log Messages To Console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %c:%L - %m%n

# Log Hibernate
log4j.logger.org.hibernate=error

# Log Just The SQL
log4j.logger.org.hibernate.SQL=debug

# Log Schema Export Update
log4j.logger.org.hibernate.tool.hbm2ddl=debug

7. Dao层
public interface BaseDao {

	public <T> void save(T t);

	public <T> void delete(T t);

	public <T> void delete(Class<T> entityClass, Integer id);

	public <T> void update(T t);

	public <T> T get(Class<T> entityClass, Integer id);

	public <T> List<T> findAll(String hql, Class<T> entityClass);

	public <T> List<T> findAll(String hql, Class<T> entityClass, 
            Object param);

	public <T> List<T> findAll(String hql, Class<T> entityClass, 
            Object[] params);

	public <T> List<T> findByPage(final String hql, final Class<T> 
            entityClass, final int firstResult, final int maxResult);

	public <T> List<T> findByPage(final String hql, final Class<T> 
            entityClass, final Object param, final int firstResult, 
            final int maxResult);

	public <T> List<T> findByPage(final String hql, final Class<T>         
            entityClass, final Object[] params,
            final int firstResult, final int maxResult);

}

public class BaseDaoImpl implements BaseDao {

	private SessionFactory sessionFactory;

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Session getSession() {
		return sessionFactory.getCurrentSession();
	}

	@Override
	public <T> void save(T t) {
		getSession().save(t);
	}

	@Override
	public <T> void delete(T t) {
		getSession().delete(t);
	}

	@Override
	public <T> void delete(Class<T> entityClass, Integer id) {
		getSession().delete(get(entityClass, id));
	}

	@Override
	public <T> void update(T t) {
		getSession().update(t);
	}

	@Override
	public <T> T get(Class<T> entityClass, Integer id) {
		return (T) getSession().get(entityClass, id);
	}

	@Override
	public <T> List<T> findAll(String hql, Class<T> entityClass) {
		return findAll(hql, entityClass, new Object[] {});
	}

	@Override
	public <T> List<T> findAll(String hql, Class<T> entityClass, Object param) {
		return findAll(hql, entityClass, new Object[] { param });
	}

	@Override
	public <T> List<T> findAll(String hql, Class<T> entityClass, 
            Object[] params) {
		Query query = getSession().createQuery(hql);
		for (int i = 0; i < params.length; i++) {
			query.setParameter(i, params[i]);
		}
		return (List<T>) query.list();
	}

	@Override
	public <T> List<T> findByPage(final String hql, Class<T> entityClass,
			final int firstResult, final int maxResult) {
		return findByPage(hql, entityClass, new Object[] {}, firstResult,
				maxResult);
	}

	@Override
	public <T> List<T> findByPage(final String hql, Class<T> entityClass,
			final Object param, final int firstResult, final int maxResult) {
		return findByPage(hql, entityClass, new Object[] { param },
				firstResult, maxResult);
	}

	@Override
	public <T> List<T> findByPage(final String hql, Class<T>   
            entityClass, final Object[] params, final int firstResult, 
            final int maxResult) {
		Query query = getSession().createQuery(hql);
		for (int i = 0; i < params.length; i++) {
			query.setParameter(i, params[i]);
		}
		query.setFirstResult(firstResult);
		query.setMaxResults(maxResult);
		return (List<T>) query.list();
	}

}

8. Service层
public interface UserService {

	public User login(User user);

}

public class UserServiceImpl implements UserService {

	private BaseDao baseDao;

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}

	@Override
	public User login(User user) {
		List<User> list = baseDao.findAll(
				"from User where username = ? and password = ?", User.class,
				new Object[] { user.getUsername(), user.getPassword() });
		if (list.size() == 1) {
			return list.get(0);
		}
		return null;
	}

}

9. Action层
public class ActionBase extends ActionSupport implements RequestAware,
		SessionAware, ApplicationAware {

	private static final long serialVersionUID = 1L;

	protected Map<String, Object> request;
	protected Map<String, Object> session;
	protected Map<String, Object> application;

	public Map<String, Object> getRequest() {
		return request;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public Map<String, Object> getApplication() {
		return application;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setApplication(Map<String, Object> application) {
		this.application = application;
	}

}

public class LoginAction extends ActionBase {

	private static final long serialVersionUID = 1L;

	private String username;
	private String password;

	private UserService userService;

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String login() throws Exception {
		User user = new User(username, password);
		User login = userService.login(user);
		if (login != null) {
			session.put("user", login);
			return SUCCESS;
		}
		return INPUT;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}

相关Jar包下载如下:
分享到:
评论
6 楼 liufengtop 2014-11-24  
com.txazo.domain.User楼主为什么没贴上去啊?
5 楼 liufengtop 2014-11-13  
能把你的完整的项目打包也发给我 我的邮箱  565060641@qq.com  谢谢啦
4 楼 yangleqiao 2014-06-10  
能把你的完整的项目打包 发给我吗 我的邮箱  leqiao88@163.com  谢谢啦O(∩_∩)O~
3 楼 a559927z 2014-02-20  
留起,有空再,配一个。   
2 楼 kaiqiangzhang001 2013-05-16  
thanks very much
1 楼 qingling600 2012-11-06  
你有没有测试啊? 我的直接报错哦。
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClassName' of bean class [com.mchange.v2.c3p0.ComboPooledDataSource]: Bean property 'driverClassName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

相关推荐

    Struts2.3.4.1 + Spring3.1.2 + Hibernate4.1.6整合包

    Struts2.3.4.1、Spring3.1.2和Hibernate4.1.6是Java Web开发中三大主流框架的特定版本,它们的整合是企业级应用开发中的常见实践,以实现模型-视图-控制器(MVC)架构。这个整合包是为了简化开发者的工作,集成了这...

    struts22.3.4.1+hibernate4.1.6+spring3.1.2整合jar包

    标题提到的"struts22.3.4.1+hibernate4.1.6+spring3.1.2整合jar包"是指将这三个特定版本的框架进行了集成,以实现更高效和无缝的协作。Struts2的2.3.4.1版本修复了一些安全漏洞并优化了性能;Hibernate的4.1.6版引入...

    struts2.3.4.1+hibernate4.1.6+spring3.1.2 整合全注解例子

    struts2.3.4.1+hibernate4.1.6+spring3.1.2 整合,全注解例子。数据库用的mysql,数据库会自动生成。整合分页、ckeditor+ckfinder.CK有些问题,上传图片不显示缩略图。

    struts2.3+spring3.1.2+hibernate4.1.6 配置说明

    在这个配置说明中,开发者使用的是Struts2.3、Spring3.1.2和Hibernate4.1.6的版本。 首先,我们需要了解这三大框架的基本作用: - **Struts2**:是一个基于MVC(Model-View-Controller)设计模式的Web应用框架,...

    数据库struts2.3.4.1+hibernate3.6.10+sping3.1.2(sql2000+proxool)+displaytag

    数据库struts2.3.4.1+hibernate3.6.10+sping3.1.2(sql2000+proxool)+displaytag 据库 struts+hibernate+sping sql2000 proxool displaytag

    struts2.3.4.1+hibernate3.6.10+sping3.1.2(sql2000+proxool)+displaytag

    struts hibernate sping sql2000 proxool displaytag 源码 实例 struts2.3.4.1+hibernate3.6.10+sping3.1.2(sql2000+proxool)+displaytag原创代码实例 sqlserver2000搭建ssh proxool连接池

    Struts2.3.4.1+Hibernate4.1.7+Spring3.1.2

    Struts2.3.4.1、Hibernate4.1.7和Spring3.1.2是经典的Java企业级开发框架组合,通常被称为SSH(Struts2、Spring、Hibernate)。这个组合在过去的许多年里被广泛用于构建Web应用程序,因为它们各自提供了一套强大的...

    strust2.34.1+spring3.1.2+hibernate4.1.6 jar

    Struts2、Spring3.1.2和Hibernate4.1.6是经典的Java Web开发框架组合,被广泛用于构建企业级应用。这个压缩包文件包含了这三个框架的特定版本,以及可能的配置文件,使得开发者可以快速搭建一个SSH(Struts2、Spring...

    搞定J2EE:STRUTS+SPRING+HIBERNATE整合详解与典型案例 (1)

    12.6 整合Struts、Spring和Hibernate实现用户管理 12.6.1 Struts、Spring和Hibernate的整合方式 12.6.2 编写用户注册画面regedit.jsp 12.6.3 编写用户登录画面login.jsp 12.6.4 编写注册控制器RegeditAction.java ...

    Maven4MyEclipse 搭建ssh2+extjs项目(4)struts2.3.4+hibernate4.2.0+spring3.1.2

    在本项目中,我们主要探讨如何使用Maven4MyEclipse搭建一个集成Struts2.3.4、Hibernate4.2.0和Spring3.1.2的SSH2(Struts2、Spring、Hibernate)项目,并结合ExtJS进行前端开发。这是一个经典的Java企业级应用架构,...

    springMVC+Mybatis3.1+spring3.1.2包含事务,注解,拦截器

    springMVC+Mybatis3.1+spring3.1.2(包含事务详解,代码诠释,含数据库文件) 展示了增、删、改、查、注解、拦截器、spring事务配置(亲测成功),sql文 件!!赶紧来下载给好评!!! web project 完全可以跑起来!...

    org.springframework.web.struts-3.1.0.M2.jar

    《Spring与Struts整合——基于org.springframework.web.struts-3.1.0.M2.jar的实践探索》 在Java Web开发领域,Spring框架以其强大的依赖注入和面向切面编程能力,以及丰富的模块支持,成为了广大开发者青睐的框架...

    搞定J2EE:STRUTS+SPRING+HIBERNATE整合详解与典型案例 (3)

    12.6 整合Struts、Spring和Hibernate实现用户管理 12.6.1 Struts、Spring和Hibernate的整合方式 12.6.2 编写用户注册画面regedit.jsp 12.6.3 编写用户登录画面login.jsp 12.6.4 编写注册控制器RegeditAction.java ...

    wicket6.0 + hibernate4.1 + spring3.1 基于J2EE的实例程序

    本文将详细探讨一个基于J2EE的实例程序,它整合了Wicket 6.0、Hibernate 4.1和Spring 3.1,充分利用这些框架的优势,构建了一个高效、灵活的应用系统。同时,该程序采用了JTA(Java Transaction API)进行事务管理,...

    spring3.1.2

    在数据访问层,Spring 3.1.2 对 JPA 和 Hibernate 的支持得到了加强,包括事务管理的优化和对 NoSQL 数据库的初步支持。它引入了新的数据存取接口,如 JdbcTemplate 和 SimpleJdbcInsert,这些简化了与数据库的交互...

    wicket6.0 + hibernate4.1 + spring3.1 基于JPA的实例程序。

    这是一个基于Java技术栈的Web应用程序实例,主要使用了Wicket 6.0、Hibernate 4.1和Spring 3.1框架,并结合JPA(Java Persistence API)进行数据持久化操作。下面将详细阐述这些技术和它们在项目中的作用。 1. ...

    DWR3.0+ hibernate4.1 + spring3.1 基于JPA JTA

    在IT领域,集成DWR3.0、Hibernate4.1、Spring3.1与JPA和JTA的技术栈,能够构建高效、灵活的企业级Web应用。以下是对这些关键技术和组件的详细解释: **DWR (Direct Web Remoting)** 是一个开源JavaScript库,允许在...

    Spring Hibernate Struts mina jdk javaee CHM格式API

    一个包,全齐了。 Hibernate-4.1.4.Final.chm Hibernate3.6.10.Final.API.chm java_ee_sdk_5_api.chm JDK.6.Documentation.chm Mina2.0.7.API.chm Spring-3.1.2.RELEASE.API.chm Struts-2.3.4.1.chm

    整合Struts+Spring+Hibernate简单例子开发.pdf

    ### 整合Struts+Spring+Hibernate简单例子开发 #### 一、项目概述与环境配置 本文档将详细介绍如何在Eclipse环境下利用MyEclipse工具整合Struts+Spring+Hibernate框架,开发一个简单的用户信息查询系统。该系统...

    搞定J2EE:STRUTS+SPRING+HIBERNATE整合详解与典型案例 (2)

    12.6 整合Struts、Spring和Hibernate实现用户管理 12.6.1 Struts、Spring和Hibernate的整合方式 12.6.2 编写用户注册画面regedit.jsp 12.6.3 编写用户登录画面login.jsp 12.6.4 编写注册控制器RegeditAction.java ...

Global site tag (gtag.js) - Google Analytics