zoukankan      html  css  js  c++  java
  • spring整合struts2

    注意:这里spring整合struts2,使用的数据库操作类是JdbcTemplate模板,该模板使用c3p0连接池。Spring将JdbcTemplate注册成一个Bean,提供给dao使用【依赖注入】。

      spring将扫描包中的所有类,将带有spring的注解【@Controller,@Repository,@Service】的类注册到容器中。

    1.jar包

    2. 配置web.xml

     3.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:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:p="http://www.springframework.org/schema/p"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                                  http://www.springframework.org/schema/beans/spring-beans.xsd
                                  http://www.springframework.org/schema/context
                                  http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://mybatis.org/schema/mybatis-spring">
        <!-- 扫描com.getword包下面的java文件,有Spring的相关注解的类,则把这些类注册为Spring的bean -->
        <context:component-scan base-package="cn.getword">
        </context:component-scan>
    
        <!-- 1.1加载properties文件 -->
        <bean id="propertyConfigurer"
              class="cn.getword.utils.EncryptablePropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:db.properties</value>
                </list>
            </property>
        </bean>
        <!-- 创建数据源 c3p0-->
        <bean id="dataSourceId" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="${jdbc.driverClassName}"></property>
            <property name="jdbcUrl" value="${jdbc.url}"></property>
            <property name="user" value="${jdbc.username}"></property>
            <property name="password" value="${jdbc.password}"></property>
        </bean>
        <!-- 创建模板 ,需要注入数据源-->
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSourceId"></property>
        </bean>
    </beans>
    View Code

    4.

  • 相关阅读:
    SQLITE3在php中的运用
    C# DllImport用法和路径问题
    ExtJs2.0学习系列(9)Ext.TabPanel之第一式
    ExtJs2.0学习系列(11)Ext.XTemplate
    ExtJs2.0学习系列(12)Ext.TreePanel之第一式
    ExtJs2.0学习系列(10)Ext.TabPanel之第二式
    ExtJs2.0学习系列(6)Ext.FormPanel之第三式(ComboBox篇)
    ExtJs2.0学习系列(15)extjs换肤
    ExtJs2.0学习系列(8)Ext.FormPanel之第五式(综合篇)
    ExtJs2.0学习系列(5)Ext.FormPanel之第二式
  • 原文地址:https://www.cnblogs.com/zhuxiang1633/p/9724707.html
Copyright © 2011-2022 走看看