首页 > 代码库 > springmvc+spring3.23+hibernate4.25框架整合(maven项目)

springmvc+spring3.23+hibernate4.25框架整合(maven项目)

整合了一下springmvc +hibernate4.希望对你们有点帮助,希望能多技术交流,需要源码请留下邮箱地址

目录结构图

注意是我的项目是在utf-8,jdk7下

相关配置

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 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.1.xsd 
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context-3.1.xsd 
                http://www.springframework.org/schema/mvc 
                http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

	<context:annotation-config />
	<!-- 使Spring支持自动检测组件,如注解的Controller -->
	<context:component-scan base-package="com.jiaoxueyun.*.web.controller" />

	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass" value=http://www.mamicode.com/"org.springframework.web.servlet.view.JstlView" />>

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" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="
                    http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-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/aop 
                    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                    http://www.springframework.org/schema/context      
                    http://www.springframework.org/schema/context/spring-context-3.1.xsd
                    http://www.springframework.org/schema/cache 
                    http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
                    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
                    
	<!-- 注解支持 -->
	<context:annotation-config />

	<!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描 -->
	<context:component-scan base-package="com">
		<!-- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> -->
	</context:component-scan>

	<!-- 属性文件位置 -->
	<bean id="annotationPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:config/properties/jdbc.properties</value>
				<value>classpath:config/properties/common.properties</value>
				<value>classpath:config/properties/log4j.properties</value>
			</list>
		</property>
	</bean>
	<!-- <context:property-placeholder location="classpath:jdbc.properties" /> -->

	<!-- 数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value=http://www.mamicode.com/"${jdbc.driverClassName}" />>spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 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.1.xsd 
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context-3.1.xsd 
                http://www.springframework.org/schema/mvc 
                http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

	<context:annotation-config />
	<!-- 使Spring支持自动检测组件,如注解的Controller -->
	<context:component-scan base-package="com.jiaoxueyun.*.web.controller" />

	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass" value=http://www.mamicode.com/"org.springframework.web.servlet.view.JstlView" />>jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
jdbc.url=jdbc\:mysql\://192.168.10.203\:3306/szxy?useUnicode\=true&characterEncoding\=UTF8
jdbc.username=root
#jdbc.password=
jdbc.password=123456
jdbc.defaultAutoCommit=true

cpool.checkoutTimeout=5000

cpool.minPoolSize=20
cpool.maxPoolSize=50

cpool.maxIdleTime=7200
cpool.maxIdleTimeExcessConnections=1800
cpool.acquireIncrement=10
log4j.xml

log4j.rootLogger=INFO,stdout,file

log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss,SSS} [%c]-[%p] %m%n 

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 
log4j.appender.file.File=${spring_springmvc_jpa.root}/shirodemo.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n

log4j.logger.org.hibernate.tool.hbm2ddl=info
很重要的 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" version="2.5">
	<display-name>test</display-name>

	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>classpath:config/properties/log4j.properties</param-value>
	</context-param>
	<!-- Spring的log4j监听器****************************************** -->
	<!-- 设置log4j配置文件路径 -->

	<!-- 开一条watchdog线程每60秒扫描一下配置文件的变化 -->
	<context-param>
		<param-name>log4jRefreshInterval</param-name>
		<param-value>600000</param-value>
	</context-param>
	
	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>
	<!-- ************************************************** -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:config/spring/applicationContext.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<servlet>
		<servlet-name>SpringDispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:config/spring/spring-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>SpringDispatcher</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<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>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value> true </param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern> /**/ /*</url-pattern>
	</filter-mapping>
	
	<servlet-mapping> 
    <servlet-name>default</servlet-name>
    <url-pattern>*.jpg</url-pattern>   
</servlet-mapping>  
<servlet-mapping>     
    <servlet-name>default</servlet-name>  
    <url-pattern>*.js</url-pattern>  
</servlet-mapping>  
<servlet-mapping>      
    <servlet-name>default</servlet-name>     
    <url-pattern>*.css</url-pattern>    
</servlet-mapping>  
<servlet-mapping>      
    <servlet-name>default</servlet-name>     
    <url-pattern>*.png</url-pattern>    
</servlet-mapping>  
<servlet-mapping>      
    <servlet-name>default</servlet-name>     
    <url-pattern>*.gif</url-pattern>    
</servlet-mapping>
	
</web-app>


springmvc+spring3.23+hibernate4.25框架整合(maven项目)