如何在没有上下文加载器的情况下将Tomcat与Spring一起使用

时间:2016-02-09 21:10:27

标签: java spring tomcat configuration

我搜索了如何使用tomcat配置spring我发现我必须将以下加载器放入上下文

<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>

我必须将spring-instrument-tomcat-x.x.jar放入tomcat lib文件夹

的applicationContext.xml

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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: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-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    <import resource="database-mysql.xml" />
    <context:load-time-weaver aspectj-weaving="off" />
    <!-- enables interpretation of the @Resource annotation to apply dependency injection through annotations -->
    <context:component-scan base-package="com.shs.dao"></context:component-scan>
    <context:component-scan base-package="com.shs.service"></context:component-scan>
    <context:component-scan base-package="com.shs.web"></context:component-scan>
    <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
    <!-- enables interpretation of the @PersistenceUnit/@PersistenceContext annotations providing convenient
    access to EntityManagerFactory/EntityManager -->
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    <bean id="contextApplicationContextProvider" class="com.shs.utils.spring.AppContext"></bean>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="Default_Persistence_Unit"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
        </property>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false"/>
                <property name="database" value="MYSQL"/>
            </bean>
        </property>
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
        </property>
    </bean>
    <bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <tx:annotation-driven  transaction-manager="jpaTransactionManager" proxy-target-class="true"/>

</beans>

但我知道有另一种方法可以配置spring而不使用上下文加载器或将jar放入tomcat lib文件夹 任何想法如何做到

提前致谢

0 个答案:

没有答案