hibernate4无法保存数据
hibernate4无法保存数据
author: hiu
以后都发文章我都备注一下作者了,hiu就是我了
初次使用hibernate4,使用getCurrentSession保存对象时无法将对象的数据保存进数据库,经过一番试验后,发现原来要配置事务才能保存数据。
保存数据失败原因:
没有配置事务,通过手动写一个事务,才能提交数据。手动写一个事务,用getCurrentSession也无法保存数据,只能使用openSession才能保存数据。
解决办法:
配置spring声明式事务,不建议使用注解来配置事务,注解配置事务,只在xml配置切面事务失败时,才用来测试。一般xml配置切面事务失败原因,找不到包,还有切面路径找不到类
说明 :
1、要注意,在web.xml配置openSessionInViewFilter用来启动hibernate,在经过url请求后,这里就会开启hibernate的session,如果不配置,就无法使用getCurrentSession了,详细配置,请看下面web.xml的配置,
2、下面的代码是用AOP配置的事务,注解方式的事务我已经注释掉了,请看UserService里面注释掉的事务注解
3、dao和service我都是用注解注入的
4、下面的几个xml文件除了applicationContext-security.xml这个配置文件外,其它的几个xml文件都是参照easyUI教程中的孙宇老师的视频配置的,有兴趣的朋友可下载下来看看,比较适合刚入门的朋友
5、项目是用maven搭建的,比较方便的,不用再去找jar包,只要在pom.xml文件配置,在连接网络的前提下就可以自动下载jar包了,可以看看下面的pom.xml文件中,我下载了那些jar包
6、因为我在spring-hibernate.xml文件配置了<prop key="hibernate.show_sql">${hibernate.show_sql}</prop> ,这个值为true时,如果执行了sql语句,就会在控制台打印出sql语句的,我在测试时,如果数据没保存进数据库,控制台是不会打印出sql语句的,成功保存数据后,打印出的信息:
2014-06-28 16:40:10 [org.hibernate.SQL]-[DEBUG] insert into union_ssh.pub_users (enabled, issys, user_account, user_desc, user_name, user_password, user_id) values (?, ?, ?, ?, ?, ?, ?) Hibernate: insert into union_ssh.pub_users (enabled, issys, user_account, user_desc, user_name, user_password, user_id) values (?, ?, ?, ?, ?, ?, ?)
下面贴出代码:
UserService:
package com.user.service; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.user.dao.UserDaoI; import com.user.model.PubUsers; import com.user.pageModel.UsersPageModel; import framework.base.dao.BaseDaoI; import framework.base.model.DataGrid; import framework.base.model.GridModel; import framework.base.model.User; @Service("userService")
@Transactional 使用注解配置事务 public class UserService { private UserDaoI userDaoi; //下面3个注解都是用来配置事务的,只要在这个类的头部加上事务注解,就能保存数据进数据库,无论使用那个,都不会影响数据是提交 /* * 如果有事务, 那么加入事务, 没有的话新建一个(默认情况下) * @Transactional(propagation=Propagation.REQUIRED) */ /*不管是否存在事务,都创建一个新的事务,原来的挂起,新的执行完毕,继续执行老的事务 * @Transactional(propagation=Propagation.REQUIRES_NEW) */ /*容器不为这个方法开启事务 * @Transactional(propagation=Propagation.NOT_SUPPORTED) */ public User save(User user) throws Exception { PubUsers t = new PubUsers(); BeanUtils.copyProperties(user, t); t.setUserId(88); t.setEnabled(1); t.setIssys(1); userDaoi.save(t); //throw new RuntimeException();//用来测试事务回滚 return user; } public BaseDaoI<PubUsers> getUserDao() { return userDao; } public UserDaoI getUserDaoi() { return userDaoi; } @Autowired public void setUserDaoi(UserDaoI userDaoi) { this.userDaoi = userDaoi; } }
UserDaoI:
package com.user.dao; import java.util.List; import com.user.model.PubUsers; public interface UserDaoI { public void save(PubUsers t); }
UserDaoImpl:
package com.user.dao.impl; import java.util.Iterator; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import com.user.dao.UserDaoI; import com.user.model.PubUsers; @Repository(value="userDao") public class UserDaoImpl implements UserDaoI { private SessionFactory sessionFactory; public SessionFactory getSessionFactory() { return sessionFactory; } @Autowired public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } /** * 获得当前事物的session * * @return org.hibernate.Session */ public Session getCurrentSession() { return sessionFactory.getCurrentSession(); } //配置事务后,直接使用这里,就可保存数据进数据库了 @Override public void save(PubUsers t) { Session session=this.sessionFactory.getCurrentSession(); session.save(t); } //这个方法是在没有配置spring事务时使用的测试,这里我已经测试过了,在UserDaoI中已经删除了这个接口 public void saveTest(PubUsers t){ //方法1,不能成功 /* Session session=this.sessionFactory.getCurrentSession(); session.save(t); */ //2,不成功 /* Session session=this.sessionFactory.getCurrentSession(); Transaction tx=session.beginTransaction(); session.save(t); tx.commit();//这里一提交,数据就保存进数据库了 */ //方法3,不成功 /* Session session=this.sessionFactory.openSession(); session.save(t); */ //方法4,事务提交后,成功保存数据到数据库 Session session=this.sessionFactory.openSession(); Transaction tx=session.beginTransaction(); session.save(t); tx.commit();//这里一提交,数据就保存进数据库了 } }
spring-hibernate.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: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.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "> <!-- JNDI方式配置数据源 --> <!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="${jndiName}"></property> </bean> --> <!-- 配置数据源 --> <!-- 阿里巴巴数据源,不用配置数据库驱动类,会根据请求的url找到相应的驱动类 --> <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="url" value="${jdbc_url}" /> <property name="username" value="${jdbc_username}" /> <property name="password" value="${jdbc_password}" /> <!-- 初始化连接大小 --> <property name="initialSize" value="0" /> <!-- 连接池最大使用连接数量 --> <property name="maxActive" value="20" /> <!-- 连接池最大空闲 --> <property name="maxIdle" value="20" /> <!-- 连接池最小空闲 --> <property name="minIdle" value="0" /> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="60000" /> <!-- <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="33" /> --> <property name="validationQuery" value="${validationQuery}" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <property name="testWhileIdle" value="true" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="25200000" /> <!-- 打开removeAbandoned功能 --> <property name="removeAbandoned" value="true" /> <!-- 1800秒,也就是30分钟 --> <property name="removeAbandonedTimeout" value="1800" /> <!-- 关闭abanded连接时输出错误日志 --> <property name="logAbandoned" value="true" /> <!-- 监控数据库 --> <!-- <property name="filters" value="stat" /> --> <property name="filters" value="mergeStat" /> </bean> <!-- 配置hibernate session工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> </props> </property> <!-- 自动扫描注解方式配置的hibernate类文件(实体类) --> <property name="packagesToScan"> <list> <value>com.*.model</value> <value>com.*.pageModel</value> </list> </property> <!-- 自动扫描hbm方式配置的hibernate文件和.hbm文件 --> <!-- <property name="mappingDirectoryLocations"> <list> <value>classpath:sy/hbm</value> </list> </property> --> </bean> <!-- 配置事务管理器 --> <bean name="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 注解方式配置事物 --> <!-- <tx:annotation-driven transaction-manager="transactionManager" /> --> <!-- 拦截器方式配置事物 --> <tx:advice id="transactionAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" /> <!-- save这里设置了事务回滚的异常,不用抛RuntimeException异常,抛出SQLException也可以回滚--> <tx:method name="save*" rollback-for="SQLException"/> <tx:method name="update*" /> <tx:method name="modify*" /> <tx:method name="edit*" /> <tx:method name="delete*" /> <tx:method name="remove*" /> <tx:method name="repair" /> <tx:method name="get*" propagation="SUPPORTS" /> <tx:method name="find*" propagation="SUPPORTS" /> <tx:method name="load*" propagation="SUPPORTS" /> <tx:method name="search*" propagation="SUPPORTS" /> <tx:method name="*" propagation="SUPPORTS" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="transactionPointcut" expression="execution(* com..service.*Service.*(..))" /> <!-- 我一开始切面使用了这个,在service中后面少了一层,导致无法开启事务,以后要注意 <aop:pointcut id="transactionPointcut" expression="execution(* com.*.service.*(..))" /> --> <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" /> </aop:config> <!-- 供spring security启动时使用 --> <bean id="userDao" class="com.user.dao.impl.UserDaoImpl"> </bean> </beans>
spring.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:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <!-- 引入属性文件 <bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:jdbc.properties</value> </property> </bean> --> <context:property-placeholder location="classpath:config.properties" /> <!-- 自动扫描包 ,主要为了使用注解注入,如果不扫描,就无法使用注解注入了,不过这里扫不扫描和事务配置无关--> <context:component-scan base-package="com.*.dao.impl,com.*.service,framework.base.dao.impl"/> </beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name></display-name> <!-- spring配置文件位置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml,classpath:spring-hibernate.xml,classpath:applicationContext-security.xml</param-value> </context-param> <!-- spring security 过滤器, 这个的位置顺序和spring的监听器启动位置没有什么关系,可以放在spring监听器的前面,也可以放置在后面。 但一定要放在struts的过滤器前面,因为如果有自定义的登录页面,当登录时,就会跳转到了struts对应的action中, 导致无法使用spring security的验证登录了,正常情况下,应该登录时,会经过自定义的MyUsernamePasswordAuthenticationFilter类的attemptAuthentication方法进行验证。 如果验证成功,则登录成功,不再执行对应的action验证登录 ;spring security验证失败,则跳回指定登录失败的页面。 --> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- spring监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- hibernate配置 --> <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> <!-- Struts2配置 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <!-- hibernate的session启动过滤器,在url请求action时启动 ,不配置这个,url请求时无法启动hibernate的session--> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- struts拦截的url后缀 --> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> <url-pattern>*.jsp</url-pattern> </filter-mapping> <!-- 修复数据库监听器 <listener> <listener-class>com.menu.listener.RepairListener</listener-class> </listener> --> <!-- 登录验证码的servlet --> <servlet> <servlet-name>CheckCode</servlet-name> <servlet-class>framework.util.CheckCode</servlet-class> </servlet> <servlet-mapping> <servlet-name>CheckCode</servlet-name> <url-pattern>/servlet/CheckCode</url-pattern> </servlet-mapping> <!-- log4j ,用来启动log4j --> <servlet> <servlet-name>Log4jInitServlet</servlet-name> <servlet-class> framework.util.Log4jInitServlet </servlet-class> <init-param> <param-name>log4jLocation</param-name> <param-value>WEB-INF/classes/log4j.properties</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <welcome-file-list> <welcome-file>/login.jsp</welcome-file> </welcome-file-list> </web-app>
applicationContext-security.xml,这个本来不打算贴出来的,因为这是spring security权限管理的配置文件,只供大家参考一下,以后有时间,再发一下这个配置的文章
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> <!-- No bean named 'springSecurityFilterChain' is defined 1、 这时发布一下你的项目,查看tomcat的webapps目录下,找到你的项目文件夹的classes文件夹有没有相关的spring.xml文件存在,不存在就会报错 2、查看web.xml文件<param-value>标签有没有引入applicationContext-security.xml这个文件 --> <!-- 不用经过spring security过滤,一般js、css都不需要过滤 --> <http pattern="/*/js/**" security="none"/> <http pattern="/common/js/**" security="none"/> <http pattern="/login.jsp" security="none"/> <!-- auto-config="true" --> <http use-expressions="true" entry-point-ref="authenticationProcessingFilterEntryPoint" > <!-- 不再在这里对url进行权限拦截,在数据库中取出url中对应的权限 <intercept-url pattern="/**" access="ROLE_USER" /> --> <!-- 单用户登陆 --> <session-management> <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" /> </session-management> <!-- 这种自定义的登录页面,不能经过security的用户信息验证,也就等于不能取出用户的权限 <form-login login-page='/login.jsp' default-target-url="/index.jsp"/> --> <!-- 尝试访问没有权限的页面时跳转的页面 --> <access-denied-handler error-page="/403.jsp"/> <custom-filter ref="loginFilter" position="FORM_LOGIN_FILTER" /> <custom-filter ref="myFilter" before="FILTER_SECURITY_INTERCEPTOR"/> <!-- 检测失效的sessionId,session超时时,定位到另外一个URL --> <session-management invalid-session-url="/sessionTimeOut.jsp" /> <!-- <custom-filter ref="logoutFilter" before="LOGOUT_FILTER"/> --> <logout invalidate-session="true" logout-success-url="/" logout-url="/logout"/> </http> <!-- 登录验证器 --> <beans:bean id="loginFilter" class="framework.security.login.MyUsernamePasswordAuthenticationFilter"> <!-- value="/loginUser.action"处理登录表单的action ,value值要以“/”开关,否则会报错 : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#3' while setting bean property 'sourceList' with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#3': Cannot resolve reference to bean 'loginFilter' while setting constructor argument with key [4]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginFilter' defined in class path resource [applicationContext-security.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'filterProcessesUrl' threw exception; nested exception is java.lang.IllegalArgumentException: userAction!login.action isn't a valid redirect URL --> <beans:property name="filterProcessesUrl" value="/user/loginUser.action"></beans:property> <!-- 验证成功后的处理 --> <beans:property name="authenticationSuccessHandler" ref="loginLogAuthenticationSuccessHandler"></beans:property> <!-- 验证失败后的处理 --> <beans:property name="authenticationFailureHandler" ref="simpleUrlAuthenticationFailureHandler"></beans:property> <beans:property name="authenticationManager" ref="authenticationManager"></beans:property> <!-- 注入DAO为了查询相应的用户 --> <beans:property name="userDao" ref="userDao"></beans:property> </beans:bean> <beans:bean id="loginLogAuthenticationSuccessHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> <beans:property name="defaultTargetUrl" value="/index.jsp"></beans:property> </beans:bean> <beans:bean id="simpleUrlAuthenticationFailureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> <!-- 可以配置相应的跳转方式。属性forwardToDestination为true采用forward false为sendRedirect --> <beans:property name="defaultFailureUrl" value="/login.jsp"></beans:property> </beans:bean> <!-- 认证过滤器 --> <beans:bean id="myFilter" class="framework.security.base.MyFilterSecurityInterceptor"> <beans:property name="authenticationManager" ref="authenticationManager" /> <beans:property name="accessDecisionManager" ref="myAccessDecisionManagerBean" /> <beans:property name="securityMetadataSource" ref="mySecurityMetadataSource" /> </beans:bean> <!-- spring security提供的用户登录验证 ,alias的值对应上面的ref="authenticationManager" --> <authentication-manager alias="authenticationManager"> <!--userDetailServiceImpl 获取登录的用户、用户权限 --> <authentication-provider user-service-ref="userDetailServiceImpl" /> </authentication-manager> <!-- 获取登录的用户、用户权限 --> <beans:bean id="userDetailServiceImpl" class="framework.security.base.MyUserDetailsService"> <beans:property name="userDao" ref="userDao"></beans:property> </beans:bean> <!-- 判断是否有权限访问请求的url页面 --> <beans:bean id="myAccessDecisionManagerBean" class="framework.security.base.MyAccessDecisionManager"> </beans:bean> <!-- 获取数据库中所有的url资源,读出url资源与权限的对应关系 --> <beans:bean id="mySecurityMetadataSource" class="framework.security.base.MySecurityMetadataSource"> </beans:bean> <!-- 未登录的切入点 --> <beans:bean id="authenticationProcessingFilterEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> <beans:property name="loginFormUrl" value="/sessionTimeOut.jsp"></beans:property> </beans:bean> </beans:beans>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>SSHMS</groupId> <artifactId>SSHMS</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name/> <description/> <!-- 指定Maven仓库 --> <repositories> <repository> <id>maven</id> <name>Maven Repository Switchboard</name> <layout>default</layout> <url>http://repo1.maven.org/maven2</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>alibaba-opensource</id> <name>alibaba-opensource</name> <url>http://code.alibabatech.com/mvn/releases/</url> <layout>default</layout> </repository> <repository> <id>alibaba-opensource-snapshot</id> <name>alibaba-opensource-snapshot</name> <url>http://code.alibabatech.com/mvn/snapshots/</url> <layout>default</layout> </repository> </repositories> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <!-- JUnit4 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11-beta-1</version> <scope>test</scope> </dependency> <!-- log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <!-- fastJson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.24</version> </dependency> <!-- spring3 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>3.1.2.RELEASE</version> </dependency> <!-- struts2 --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.16.3</version> <!-- 如果有hibernate时要去除这个,因为hibernate也有这个类,不能以这个代替hibernate的那个,否则会出错 --> <exclusions> <exclusion> <groupId>javassist</groupId> <artifactId>javassist</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.3.16.3</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.3.16.3</version> </dependency> <!-- 加入mysql驱动依赖包 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.27</version> </dependency> <!-- 加入druid数据源依赖包 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.0</version> </dependency> <!-- spring事务切面的包 --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.7.4</version> </dependency> <!-- hibernate4 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.7.Final</version> </dependency> <!-- spring security --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>3.2.4.RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>3.2.4.RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>3.2.4.RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.2.8.RELEASE</version> <scope>compile</scope> </dependency> <!-- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/web/context/request/async/CallableProcessingInterceptor --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.2.8.RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> <scope>compile</scope> <optional>true</optional> </dependency>
<!--注解事务要引入的包--> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
也贴上一张项目的架构图吧
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。