eclipse配置S2SH搭建过程及错误解决

PS:半年没摸S2SH框架 不知道怎么配了。以前都是myeclipse自己来配置。
so准备拿eclipse自己配置下练练,问龙哥要了以前的代码作参考。

mark一下  老了记性不行~!

简单数据验证、插入操作DEMO下载地址

(注意环境区别)

要资源:
spring-framework-3.1.3.RELEASE 
传送门
struts-2.3.7-all  传送门
hibernate-distribution-3.6.0.Beta3-dist  传送门 
eclipse  传送门
jdk7.0  传送门

tomcat 7  传送门

一、目录结构
图片
 

二、所有的jar包  如下图
 

图片

图片

三、遇到问题
其中很明显下载框架包里面没有的jar包
commons-pool-1.6.jar 
apache的通用池jar包  struts2.3.7里面没有提供  传送门

slf4j-nop-1.6.1.jar  hibernate没有提供  传送门

貌似可以了,但是各种红色....... 心里拔凉啊  
真心eclipse麻烦 ,但是它没myeclipse占资源

错误1
使用Spring
集成hibernate3,在添加声明式事务管理后
java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException 
错误原因:缺少
aspectjweaver-1.5.3.jar   传送门 

错误2
出现了java.lang.NoClassDefFoundError:的错误

org.springframework.beans.factory.BeanDefinitionStoreException: 

  1. Caused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor  
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [SpringConfig_Jdbc.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor(省略)...Caused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor  
错误原因:缺少 
aopalliance.jar  传送门
错误3
java.lang.NoClassDefFoundError: edu/emory/mathcs/backport/java/util/concurrent/BlockingQueue
上面情况还会导致在启动tomcat时出现以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [Beans.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Error configuring from file:/D:/Eclipse/Work/workspace/.metadata/.me_tcat/webapps/SSH/WEB-INF/classes/ehcache.xml. Initial cause was Error configuring from input stream. Initial cause was Invalid byte 1 of 1-byte UTF-8 sequence.
错误原因:缺少
backport-util-concurrent.jar     传送门
 
问题4
ok 最后跑起来了,但是出现下面的情况
***********************************************************************
                                                           WARNING!!!                                                       *
                                                                                                                                       *
* >>> FilterDispatcher <<< is deprecated! Please use the new filters! *
                                                                                                                                       *
                   This can be a source of unpredictable problems!                     *
                                                                                                                                       *
                         Please refer to the docs for more details!                         *
                     http://struts.apache.org/2.x/docs/webxml.html ;                      *
                                                                                                                                       *
***********************************************************************  
原因:

自Struts 2.1.3后,FilterDispatcher已被标注为过时
在Struts2的官方网上会看到:To split up the the dispatcher phases, FilterDispatcher is deprecated since Struts 2.1.3.
即从Struts 2.1.3起已被标注为过时的,该用StrutsPrepareAndExecuteFilter
 

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher    <!--  这一句修改为最新的  -->
</filter-class> 
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> 
改为:

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

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> 

-------------- end  配置完成-------------------------
附:
web.xml
struts.xml  
hibernate.cfg.xml  
applicationContext-comms.xml  
applicationContext-beans.xml
applicationContext-actions.xml  

 文件:web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	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_2_5.xsd">
 <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>
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

文件:struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<!--常用常量配置-->
	<!--打开开发模式-->
	<constant name="struts.devMode" value="false"></constant>
	<!-- 指定每次请求到达,重新加载资源文件 -->
	<constant name="struts.i18n.reload" value="true" />
	<!-- 指定每次配置文件更改后,自动重新加载 -->
	<constant name="struts.configuration.xml.reload" value="true" />
	<!-- 默认的视图主题 -->      
	<constant name="struts.ui.theme" value="simple" />
	<!--最大文件上传大小-->
	<constant name="struts.multipart.maxSize" value="10485760"></constant>
	<include file="struts-login.xml"/>
</struts>    

文件:hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>

	<!-- hibernate dialect -->
	<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
	<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
	<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=Test</property>
	<property name="hibernate.connection.username">sa</property>
	<property name="hibernate.connection.password">f123456!</property>
	<!-- JDBC connection properties (end) -->


	<!-- 显示sql语句 -->
	<property name="show_sql">true</property>
	<!-- 自动更新表结构 -->
	<!--<property name="hbm2ddl.auto">update</property>-->

	<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%使用c3p0连接池%%%%%%%%%%%%%%%%%%%%%%%%%% -->
	<!-- 最大连接数 -->
	<property name="hibernate.c3p0.max_size">25</property>
	<!-- 最小连接数 -->
	<property name="hibernate.c3p0.min_size">5</property>
	<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
	<property name="hibernate.c3p0.timeout">1800</property>
	<!-- 最大的PreparedStatement的数量 -->
	<property name="hibernate.c3p0.max_statements">100</property>
	<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
	<property name="hibernate.c3p0.idle_test_period">120</property>
	<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
	<property name="hibernate.c3p0.acquire_increment">2</property>
	<!-- 每次都验证连接是否可用 -->
	<property name="hibernate.c3p0.validate">true</property>


	<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%使用EHCache二级缓存%%%%%%%%%%%%%%%%%%%%%%%%%% -->
	<property name="cache.use_second_level_cache">true</property>
	<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
	<property name="hibernate.cache.use_query_cache">true</property>


	<!-- 声明映射文件 -->
<!-- 	<property name="myeclipse.connection.profile">book</property> -->

	<mapping resource="com/adminSystem/entity/UserInfo.hbm.xml" />

</session-factory>
</hibernate-configuration>

文件:applicationContext-comms.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: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-3.0.xsd
	http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-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">
	
	
	<context:annotation-config/>

	
	<!--配置Hibernate的SessionFactory-->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
	</bean>
		<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!--配置事务管理器-->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<!--配置事务的传播特性-->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED"/>
			<tx:method name="add*" propagation="REQUIRED"/>
			<tx:method name="update*" propagation="REQUIRED"/>
			<tx:method name="delete*" propagation="REQUIRED"/>
			<tx:method name="init*" propagation="REQUIRED"/>
			<tx:method name="*" propagation="REQUIRED" read-only="true"/>
		</tx:attributes>
	</tx:advice>
	
	<!--哪些类的哪些方法要使用事务-->
	<aop:config>
		<aop:pointcut expression="execution(* com.adminSystem.service.impl.*.*(..))" id="allServiceMethod"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod"/>
	</aop:config>
	
	
</beans>



  文件: applicationContext-beans.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: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-3.0.xsd
	http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-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">
	<context:annotation-config />  
<!-- 	<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />  -->
	
	<!--注入数据访问层对象-->
	<bean id="userDAO" class="com.adminSystem.dao.impl.UserDAOImpl">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<!--注入业务逻辑组件-->
	<bean id="userService" class="com.adminSystem.service.impl.UserServiceImpl">
	</bean>

	
</beans>



文件:applicationContext-actions.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: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-3.0.xsd
		http://www.springframework.org/schema/context 
	    http://www.springframework.org/schema/context/spring-context-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">

	<!--登录管理 -->
	<bean id="loginAction" class="com.adminSystem.web.LoginAction"></bean>
	<bean id="userAction" class="com.adminSystem.web.UserAction"></bean>


</beans>


注意 实现接口的方法要继承 HibernateDaoSupport哦,要不....你懂得   
后续有问题再补..... 




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值