• 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.

  • 相关阅读:
    领料单取整
    财务应付金额对不上的
    销售订单计算交期
    辅助单位启用
    K3CLOUD日志目录
    QLIKVIEW-日期格式,数字格式写法
    MRP运算报错-清除预留
    整单折扣后 财务、暂估应付价税合计对不上的问题处理
    BZOJ 2976: [Poi2002]出圈游戏 Excrt+set
    BZOJ 3060: [Poi2012]Tour de Byteotia 并查集
  • 原文地址:https://www.cnblogs.com/zhuxiang1633/p/9724707.html
Copyright © 2020-2023  润新知