用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

购物平台

2018-06-27 作者:hello0991举报

[java]代码库

<?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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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/tx 
	http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/mvc  
	http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <!-- 配置数据库相关参数 -->
    <context:property-placeholder location="classpath:db.properties"/>

    <!-- 配置自动扫描的包 -->
     <context:component-scan base-package="com.shop.dao"></context:component-scan>
    <context:component-scan base-package="com.shop">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="user" value="${jdbc.user}"></property>
        <property name="password" value="${jdbc.password}"></property>
        <property name="driverClass" value="${jdbc.driverClass}"></property>
        <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
        <!-- 配置其他属性 -->

    </bean>

    <!-- 配置SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">true</prop>
            </props>
        </property>

        <property name="packagesToScan">
            <list>
                <value>com.shop.model</value>
                 <value>com.shop.dao</value>
                 
            </list>
        </property>
    </bean>

    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">

        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>

    </bean>
    

    <!-- 开启注解事务-->
    <tx:annotation-driven transaction-manager="transactionManager"/>


    <!-- 配置扫描Dao接口包,动态实现Dao接口并注入spring容器中 -->
    <!-- 使用MapperScannerConfigurer是为了防止提前它初始化qlLSessionFactory,而此时可能properties文件还未加载 -->
    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        &lt;!&ndash; 注入sqlSessionFactory &ndash;&gt;
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>

        &lt;!&ndash; 给出需要扫描Dao接口包 &ndash;&gt;
        <property name="basePackage" value="org.seckill.dao"/>
    </bean>-->

    <!-- 自动注册 DefaultAnnotationHandlerMapping 与 AnnotationMethodHandlerAdapter 两个bean,
    是spring MVC为@Controllers分发请求所必须的 -->
    <mvc:annotation-driven/>

</beans>

[源代码打包下载]




分享到:
更多

网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。