springMVC3.2+spring3.2.4+hibernate 4.2.4+MySQL环境配置

摘要 c3p0连接池,springMVC3.2+spring3.2.4+hibernate 4.2.4+MySQL简单的环境配置,超基础,版本比较新了。配置一实现简单的用户登录功能为基础。

jar包,百度:http://pan.baidu.com/s/1dDpIElj

ps:通过三个xml文件配置,不同的版本头文件不同,建议从源文件考取。请注意文中所有路径

一、applicationContext.xml  Spring的配置


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?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"
        xsi:schemaLocation="
        http: //www.springframework.org/schema/beans
            http: //www.springframework.org/schema/beans/spring-beans.xsd
            http: //www.springframework.org/schema/tx
            http: //www.springframework.org/schema/tx/spring-tx-3.2.xsd
            http: //www.springframework.org/schema/aop
            http: //www.springframework.org/schema/aop/spring-aop-3.2.xsd
            http: //www.springframework.org/schema/context
            http: //www.springframework.org/schema/context/spring-context-3.2.xsd
            "
            >
 
            
<!-- 数据源配置,使用应用内的c3p0数据库连接池 -->
     <bean id= "dataSource"  class = "com.mchange.v2.c3p0.ComboPooledDataSource" >
         <property name= "driverClass"  value= "com.mysql.jdbc.Driver"  />
         <property name= "jdbcUrl"  value= "jdbc:mysql://localhost:3306/jumperworkdb"  />
         <property name= "user"  value= "root"  />
         <property name= "password"  value= ""  />
     </bean>
 
<!-- 数据源配置方法二,使用jdbc链接 --> 
     <!-- <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:3306/jumperworkdb" ></property>  
             <property name= "username"  value= "root" ></property>  
             <property name= "password"  value= "" ></property>
                 
        </bean>   -->  
          
            
<!-- Hibernate配置 -->
     <bean id= "sessionFactory"
         class = "org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
         <property name= "dataSource"  ref= "dataSource"  />
     
         <property name= "hibernateProperties" >
             <props>
                 <prop key= "hibernate.dialect" >org.hibernate.dialect.MySQLDialect</prop><!--方言配置-->
                 <prop key= "hibernate.show_sql" > true </prop><!--显示sql语句-->
             </props>
         </property>
         
         <property name= "mappingResources" >
             <list>
                 <value>com/ksdhc/bo/user.hbm.xml</value>
             </list>
         </property>
         
     </bean>
     
     <!-- dao层配置 -->
     <bean id= "userDao"  class = "com.ksdhc.dao.imp.UserDaoImp" >
         <property name= "sessionFactory"  ref= "sessionFactory" ></property>
     </bean>
     <bean id= "userServices"  class = "com.ksdhc.services.imp.UserServicesImp" >
         <property name= "userDao"  ref= "userDao" ></property>
     </bean>
</beans>

二、springmvc_servlet.xml    springMVC的配置


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?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"
     xmlns:mvc= "http://www.springframework.org/schema/mvc"
     xsi:schemaLocation="
       http: //www.springframework.org/schema/beans
       http: //www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http: //www.springframework.org/schema/context
       http: //www.springframework.org/schema/context/spring-context-3.2.xsd
       http: //www.springframework.org/schema/mvc
       http: //www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
   ">
     <!-- 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
     <context:component-scan base- package = "com"  />
 
     <!-- 开启Bean的注解配置 -->
     <context:annotation-config></context:annotation-config>
     
     <!-- 开启AOP注解方式  
     <aop:aspectj-autoproxy />-->
 
     <!-- 支持spring3. 0 新的mvc注解 -->
     <mvc:annotation-driven />
     <mvc:resources location= "/Resource/"  mapping= "/Resource/**" />
     <!--对模型视图名称的解析,即在模型视图名称添加前后缀 -->
     <bean
         class = "org.springframework.web.servlet.view.InternalResourceViewResolver" >
         <!-- 如果使用jstl的话,配置下面的属性 -->
         <property name= "prefix"  value= "/" ></property>
         <property name= "suffix"  value= ".jsp" ></property>
     </bean>
</beans>

三、web.xml


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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>JumperWork</display-name>
   <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
   
   
      <!-- 定义spring监听 -->
      <!-- Spring配置 -->
   <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>
  
  <!-- SpringMVC配置 -->
   <servlet>
         <servlet-name>JumperWork</servlet-name>
         <servlet- class >
             org.springframework.web.servlet.DispatcherServlet
         </servlet- class >
         <init-param>
             <param-name>contextConfigLocation</param-name>
             <param-value>classpath*:/springmvc-servlet.xml</param-value>
             
         </init-param>
         <load-on-startup> 1 </load-on-startup>
  </servlet>
   
<servlet-mapping>
         <servlet-name>JumperWork</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>  
 
</web-app>

四、user.hbm.xml  Hibernate属性配置


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version= "1.0"  encoding= "UTF-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC 
     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
     "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
 
<hibernate-mapping >
     
     < class  name= "com.ksdhc.bo.User"  table= "user_regist" >
         <id name= "userID"  column= "UserID" >
             <generator  class = "native" />
         </id>
         <property name= "userName"  column= "UserName"  type= "java.lang.String"   />
         <property name= "userEmail"  column= "UserEmail"  type= "java.lang.String"   />
         <property name= "userPass"  column= "UserPass"  type= "java.lang.String"   />
         
     </ class >
     
</hibernate-mapping>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值