s2sh整合案例-学生信息管理系统(一)

s2sh整合案例-学生信息管理系统(一)

    接下来花大概3-4篇博文的时间来讲讲我自己采用Struts2,Hibernate3,Spring3,jquery-easyui等框架搭建的一个小案例:学生信息管理系统。其中后端是s2sh,前端是jquery-easyui。这个案例比较简单,目的主要是为了如何采用s2sh搭建属于自己的架构并将其应用在某些案例上。搭建完成之后,我个人觉得是挺有意思的,以后若是想扩充功能,可以在我这个的基础山进行扩充。比如可以加入log日志,加入quartz执行定时任务,加入highchartz绘制报表等等。

    废话不多说了,搭建一个java web的项目,第一步当然是加入jar包啦,可以来我这里下载:s2sh整合jar包。放入webContent下WEB-INF的lib文件夹下。接着建立项目的包目录结构。下图是项目jar的整体展示:

     其中,com.steadyjack.server.util下的所有类,已经在前面这两篇博文进行了介绍,而且源代码也在那里了,可以到这里获取源代码:com.steadyjack.server.util-1  com.steadyjack.server.util-2

     好了,接下来配置web.xml(注意:创建dynamicWebProject时候,注意选择2.5的版本,让其自动生成web.xml文件)。下面是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_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>S2SHStudentInfoManage</display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>

	<!-- 上下文应用参数 指向spring的配置文件的名称和位置 : spring的配置 (alt+/,找到contextLoaderListener)-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:configs/spring/applicationContext.xml</param-value>
	</context-param>

	<!-- ServletContextListener用于在web项目启动的时候加载Spring的IOC容器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<!-- 配置struts2过滤器 : StrutsPrepareAndExecuteFilter-->
	<filter>
		<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<!-- 配置字符集编码: UTF-8 CharacterEncodingFilter(参考网上配置:spring 字符集编码)-->
	<filter>
		<filter-name>characterEncodingFilter</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>  
   		<init-param>  
	        <param-name>forceEncoding</param-name>  
	        <param-value>true</param-value>  
    	</init-param>  
	</filter>
	
	<filter-mapping>
		<filter-name>characterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

 

 

 

     下面是配置applicationContext.xml和jdbc-properties.properties(数据库配置文件)

      applicationContext.xml文件:

 

<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:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/aop 
  http://www.springframework.org/schema/aop/spring-aop-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/tx 
  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring   
  http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">
	
	<!-- 添加注解支持 -->
	<context:annotation-config />
	
	<!-- 添加Spring需要进行注解扫描的包 : server层 和 web层-->
	<context:component-scan base-package="com.steadyjack.server,com.steadyjack.web" />
	
	<!-- 加载数据配置文件  jdbc.properties : 其中包括了数据库的url user password driverClassName; c3p0数据库连接池的其他参数
		 (具体可参考网上配置: c3p0配置) -->
	<context:property-placeholder location="classpath:configs/spring/jdbc-properties.properties" />
	
	<!-- 配置数据源 : 在这里使用的是spring提供的DriverManagerDataSource,其实可以配置为c3p0的-->
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="${jdbc.driverClassName}"></property>
		<property name="url" value="${jdbc.url}"></property>
		<property name="username" value="${jdbc.username}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean>

	<!-- 配置Hibernate的sessionFactory,让Spring的IOC容器管理Hibernate的SessionFactory : 
	            其中需要配置属性: 数据源;hibernate的属性;model层下的model,即注解的model-->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
			</props>
		</property>
		<!-- <property name="annotatedClasses">
			<list>
				<value>com.steadyjack.server.model.User</value>
				<value>com.steadyjack.server.model.Grade</value>
				<value>com.steadyjack.server.model.Student</value>
			</list>
		</property> -->
		<property name="packagesToScan" value="com.steadyjack.server.model"></property>
	</bean>

	<!-- 配置事务管理器 : HibernateTransactionManager: 其中需要配置sessionFactory属性-->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!-- 配置事务传播特性 -->
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="*Save*" propagation="REQUIRED" />
			<tx:method name="*Delete" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="get*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>

	<!-- 配置事务切面,并关联事务传播属性(配置哪些类的哪些方法参与事务) -->
	<aop:config>
		<aop:pointcut expression="execution(* com.steadyjack.server.service.*.*(..))" id="txPointCut"/>
		<aop:advisor advice-ref="transactionAdvice" pointcut-ref="txPointCut"/>
		<!-- <aop:advisor pointcut="execution(* com.steadyjack.server.service.*.*(..))"
			advice-ref="transactionAdvice" /> -->
	</aop:config>


</beans>


     jdbc-properties.properties(数据库配置文件):

 

 

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=123456
jdbc.url=jdbc:mysql://localhost:3306/db_studentInfo?useUnicode=true&characterEncoding=UTF-8


     至此,项目配置方面就搞完了,在上面的配置文件中我提出了自己的一些建议, 博友们可以参照自身需要进行修改!!

 

     这个时候可以启动一下项目了,发现没报错,就是OK的了!!!如果有问题,可以下面留言!!!个人QQ:1948831260

发布了140 篇原创文章 · 获赞 253 · 访问量 64万+
展开阅读全文

s2sh整合问题,弄了一天了都没弄出来,拜托大家了!

12-05

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [C:\Program Files\apache-tomcat-6.0.28\webapps\System\WEB-INF\classes\applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:785) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445) at org.apache.catalina.core.StandardService.start(StandardService.java:519) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:581) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2722) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1124) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at org.springframework.transaction.config.TxAdviceBeanDefinitionParser.getBeanClass(TxAdviceBeanDefinitionParser.java:69) at org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:66) at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1335) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1325) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) ... 37 more Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 55 more 配置文件代码:web.xml [code="java"]<?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"> <!-- 开始监听 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置spring监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:*Context.xml</param-value> </context-param> <filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- <filter> <filter-name>lazyLoadingFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>false</param-value> </init-param> </filter> <filter-mapping> <filter-name>lazyLoadingFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> --> <!-- 配置OpenSessionInViewFilter,必须在struts,用来解决could not initialize proxy-no Session报错问题,配置自己写的filter --> <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> <!-- <listener> <listener-class>com.hyit.ttmsoge.listener.FactoryLoaderListener</listener-class> </listener> --> <welcome-file-list> <welcome-file>Login.html</welcome-file> </welcome-file-list> </web-app> [/code] applicationContext: [code="java"]<?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-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"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"> </property> <property name="url" value="jdbc:mysql://localhost:8080/ttmsoge"> </property> <property name="username" value="root"></property> <property name="password" value="0429"></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.MySQLDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <property name="mappingResources"> <list> <value>com/hyit/ttmsoge/model/Register.hbm.xml</value> <value>com/hyit/ttmsoge/model/User.hbm.xml</value> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 配置Advice(事务的传播特性) --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="get*" propagation="SUPPORTS" read-only="true" /> <tx:method name="search*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> </beans> [/code] 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览