zoukankan      html  css  js  c++  java
  • spring环境搭建

    1.导入jar包:

    2.配置文件 — applicationContext.xml:

       添加schema约束,位置:spring-framework-3.2.0.RELEASE—》docs—》spring-framework-reference—》html—》xsd-config.html

    再配置service

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
                                  http://www.springframework.org/schema/beans/spring-beans.xsd">
        <!-- 配置service 
            <bean> 配置需要创建的对象
                id :用于之后从spring容器获得实例时使用的
                class :需要创建实例的全限定类名
        -->
        <bean id="userServiceId" class="com.itheima.a_ioc.UserServiceImpl"></bean>
    </beans>
    applicationContext.xml

    其次,里面可以配置加载jdbc属性文件、数据源、spring框架用于整合Hibernate的工厂bean、事务管理器、组件扫描、引入注解解析器、 事务注解 等。如:

    <?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"
        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/aop
                            http://www.springframework.org/schema/aop/spring-aop.xsd
                            http://www.springframework.org/schema/tx 
                            http://www.springframework.org/schema/tx/spring-tx.xsd">
        
        <!-- 加载jdbc属性文件 -->
        <context:property-placeholder location="classpath:jdbc.properties"/>
                            
        <!-- 数据源 -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="${driverClass}"/>
            <property name="jdbcUrl" value="${jdbcUrl}"/>
            <property name="user" value="${user}"/>
            <property name="password" value="${password}"/>
        </bean>
        <!-- spring框架用于整合Hibernate的工厂bean -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <!-- 注入Hibernate相关的属性 -->
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
                </props>
            </property>
            <!-- 注入Hibernate的映射文件 -->
            <property name="mappingDirectoryLocations">
                <list>
                    <value>classpath:com/itheima/bos/domain</value>
                </list>
            </property>
        </bean>
        
        <!-- 事务管理器 -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        
        <!-- 组件扫描 -->
        <context:component-scan base-package="com.itheima.bos"/>
        <!-- 引入注解解析器 -->
        <context:annotation-config/>
        <!-- 事务注解 -->
        <tx:annotation-driven />
    </beans>
    applicationContext.xml
  • 相关阅读:
    图像处理之基础---图像缩放中的一些 灰度插值算法
    多媒体开发之---h264 取流解码分析
    校验算法之二进制反码求和
    c++学习笔记之基础---类内声明函数后在类外定义的一种方法
    图像增强---中值滤波
    阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第4节 多态_19_使用多态的好处
    阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第4节 多态_18_多态中成员方法的使用特点
    阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第4节 多态_17_多态中成员变量的使用特点
    阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第4节 多态_16_多态的格式与使用
    阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第4节 多态_15_多态的概述
  • 原文地址:https://www.cnblogs.com/jiao-/p/8511968.html
Copyright © 2011-2022 走看看