0

複数の戦争があるTomcatでアプリケーションを実行しています。

  1. War1 は、データベースのプロビジョニングに使用される Web アプリです。
  2. War2 は、Web サービス経由でデータをアップロードするためのものです。
  3. War3 は、Web サービス経由でデータを取得するためのものです。
  4. War4 は、ダッシュボードでデータを表示するために使用される別の Web アプリです。

hibernate/jpa と spring を使用します。クラスには注釈が付けられており、それらのいずれにも persistence.xml はありません。すべての構成は、Spring コンテキスト ファイルと注釈にあります。春のファイルは次のとおりです。

<?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:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:flow="http://www.springframework.org/schema/webflow-config"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:cache="http://www.springframework.org/schema/cache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
          http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
          http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
          http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
">
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <!-- Directory to scan for repository classes -->
    <jpa:repositories
        base-package="com.blah.db.model.repository" />
    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>/WEB-INF/configuration.properties</value>
            </list>
        </property>
    </bean>
    <cache:annotation-driven />
        <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/>
        <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
                    p:config-location="/WEB-INF/ehcache.xml"
                    p:shared="true"/>
    <context:component-scan base-package="com.blah.db.model.service" />
    <context:component-scan base-package="com.blah.business.objects" />
    <context:component-scan base-package="com.blah.data.access.objects" />
    <context:component-scan base-package="com.blah.common" />

    <bean class="org.springframework.orm.jpa.JpaTransactionManager"
      id="transactionManager">
        <property name="entityManagerFactory"
            ref="entityManagerFactory" />
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
        </property>
    </bean>
    <bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="packagesToScan" value="com.blah.db.model"  />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="${hibernate.generate.ddl}" />
                <property name="database" value="${hibernate.database}" />
                <property name="showSql" value="${show.sql}" />
            </bean>
        </property>
        <property name="jpaProperties">
            <map>
                <entry key="hibernate.default_schema" value="${default.schema}"/>
                <entry key="hibernate.dialect" value="${jdbc.hibernate.dialect}"/>
                <entry key="hibernate.id.new_generator_mappings" value="${new.generator.mappings}"/>
                <entry key="hibernate.cache.region.factory_class" value="${hibernate.cache.factory.class}"/>
                <entry key="hibernate.cache.use_second_level_cache" value="${hibernate.use.second.level.cache}"/>
                <entry key="hibernate.cache.use_query_cache" value="${hibernate.use.query.cache}"/>
                <entry key="net.sf.ehcache.configurationResourceName" value="${ehcache.config.file}"/>
            </map>
        </property>
    </bean>
    <bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://127.0.0.1:5432/blah" />
        <property name="username" value="postgres" />
        <property name="password" value="password" />
    </bean>
    <bean id="openSessionInViewInterceptor" class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor">
        <property name="entityManagerFactory">
            <ref local="entityManagerFactory"/>
        </property>
        <property name="jpaProperties">
            <map>
                <entry key="singleSession" value="true"/>
                <entry key="flushModeName" value="FLUSH_AUTO"/>
            </map>
        </property>
    </bean>
</beans>

すべての war が単一の持続性ユニットを使用するようにするにはどうすればよいですか? ehcache を使用できるようにしたいのですが、それらがすべて独自の PU を使用している場合、使用できないことはわかっています。

私の唯一の選択肢は、JavaEE に移行してすべてを EAR にパッケージ化することですか?

ありがとう!

4

1 に答える 1

0

アプリケーション間で永続化ユニットを共有するということは、共通のクラスを共有 tomcat フォルダーにデプロイすることを意味します。これは、ロードされたショットガンを舌で掃除するのと同じくらい安全です。

キャッシュを共有する必要がある場合は、ehcache を使用して、terracotta をオフヒープ キャッシュとして使用します。このソリューションはシンプルで、間違いなくリスクが低くなります。

もう 1 つのオプションは、これら 4 つのアプリをより大きなアプリにマージすることです。これは、すべてのアプリが同じデータを共有する場合に適しています。

于 2012-10-17T21:24:18.983 に答える