春季自动扫描中的过滤器组件

huangapple go评论59阅读模式
英文:

Spring Filter components in auto scanning

问题

我有一个 Spring MVC 应用程序(一个面向 Java 平台的应用程序框架和控制反转容器)。该框架的核心功能可用于任何 Java 应用程序,但也有用于在 Java EE(企业版)平台上构建 Web 应用程序的扩展),使用了 Spring 过滤功能,现在使用 Spring 过滤器。

<context:component-scan base-package="com.pastis">
    <context:exclude-filter type="assignable" expression="com.pastis.security.controller.SecurityManagerController"/>
    <context:exclude-filter type="assignable" expression="com.pastis.pq.workflow.web.controller.WorkflowController"/>
    <context:exclude-filter type="regex" expression="com.pastis.pq.workflow.web.*" />
    <context:exclude-filter type="regex" expression="com.pastis.security.*" />
    <context:exclude-filter type="regex" expression="com\.pastis\.security\..*" />
</context:component-scan>

<jpa:repositories base-package="com.pastis.repositories"/>

还尝试过:

<context:annotation-config />
<context:component-scan base-package="com.pastis">
    <context:component-scan base-package="com.pastis.security">
        <context:exclude-filter type="assignable" expression="com.pastis.security.controller.SecurityManagerController"/>
    </context:component-scan>
    <context:component-scan base-package="com.pastis.pq">
        <context:exclude-filter type="assignable" expression="com.pastis.pq.workflow.web.controller.WorkflowController"/>
        <context:exclude-filter type="assignable" expression="com.pastis.pq.workflow.web.controller.WorkflowAdminController"/>
    </context:component-scan>
</context:component-scan>

但是我在 WorkflowController 中遇到了问题,并且这个控制器:

com.pastis.security.controller.SecurityManagerController

然而,当我启动应用程序时,我得到了以下错误:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityManagerController':

在 servlet 配置文件中:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/data/jpa
       http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
       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">

    <!-- 使用注解注入依赖 -->
    <context:annotation-config />
    <context:component-scan base-package="com.pastis.pq" use-default-filters="false" >
        <context:include-filter type="aspectj" expression="com.pastis.pq.web.endpoint.*" />
        <!--context:include-filter type="annotation" expression="com.pastis.pq.web."/--><!-- 这一行被注释掉了 -->
    </context:component-scan>

    <jpa:repositories base-package="com.pastis.pq.repositories"/>

    <!-- 主数据源 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.h2.Driver" />
        <property name="url" value="jdbc:h2:mem:~/test2;DB_CLOSE_DELAY=-1" />
        <property name="username" value="sa" />
        <property name="password" value="" />
    </bean>

    <!-- 事务管理 -->
    <tx:annotation-driven/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <!-- Spring Data 仓库 -->
    <jpa:repositories base-package="com.pastis.pq.repositories"/>

    <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
        <property name="database" value="H2" />
        <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceUnitName" value="pastis-entities" />
        <property name="packagesToScan">
            <array>
                <value>com.pastis.pq.model</value>
            </array>
        </property>
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="jpaProperties">
            <props>
                <prop key="eclipselink.target-database">org.eclipse.persistence.platform.database.OraclePlatform</prop>
                <prop key="eclipselink.target-server">WebLogic</prop>
            </props>
        </property>
    </bean>

    <!-- 可自定义的数据库配置 -->
    <bean id="dataConfig" class="com.pastis.commons.services.SystemConfig">
        <constructor-arg index="0" value="test-config.properties"/>
        <constructor-arg index="1" ref="dataSource"/>
    </bean>

</beans>

在运行测试时的控制台输出:

2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - 创建共享的 singleton bean 实例 'securityManagerController'
2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - 创建共享的 singleton bean 实例 'securityManagerController'
2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - 创建 bean 'securityManagerController' 的实例
2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - 创建 bean 'securityManagerController' 的实例
2020-10-08 10:46:57,317 [DEBUG] org.springframework.beans.factory.annotation.InjectionMetadata - 在类 [com.pastis.security.controller.SecurityManagerController] 上注册了注入元素:
英文:

I have a Spring MVC app. ( an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE (Enterprise Edition) platform) using this Spring filtering, Now using spring filter

 &lt;context:component-scan base-package=&quot;com.pastis&quot;  &gt;
&lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.security.controller.SecurityManagerController&quot;/&gt;
&lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.pq.workflow.web.controller.WorkflowController&quot;/&gt;
&lt;context:exclude-filter type=&quot;regex&quot;      expression=&quot;com.pastis.pq.workflow.web.*&quot; /&gt;
&lt;context:exclude-filter type=&quot;regex&quot;      expression=&quot;com.pastis.security.*&quot; /&gt;
&lt;context:exclude-filter type=&quot;regex&quot;      expression=&quot;com\.pastis\.security\..*&quot; /&gt;
&lt;/context:component-scan&gt;
&lt;jpa:repositories base-package=&quot;com.pastis.repositories&quot;/&gt;

also tried:

&lt;context:annotation-config /&gt;
&lt;context:component-scan base-package=&quot;com.pastis&quot; /&gt;
&lt;context:component-scan base-package=&quot;com.pastis.security&quot;&gt;
&lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.security.controller.SecurityManagerController&quot;/&gt;
&lt;/context:component-scan&gt;
&lt;context:component-scan base-package=&quot; com.pastis.pq&quot;&gt;
&lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.pq.workflow.web.controller.WorkflowController&quot;/&gt;
&lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.pq.workflow.web.controller.WorkflowAdminController&quot;/&gt;
&lt;/context:component-scan&gt;

but I have a problem with the WorkflowController

and this controller:

com.pastis.security.controller.SecurityManagerController

nevertheless when I start the app. I got this error:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;securityManagerController&#39;:

the servlet-xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
xmlns:jpa=&quot;http://www.springframework.org/schema/data/jpa&quot;
xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
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">
&lt;!-- Use annotations to inject stuff --&gt;
&lt;context:annotation-config /&gt;
&lt;context:component-scan base-package=&quot;com.pastis.pq&quot; use-default-filters=&quot;false&quot; &gt;
&lt;context:include-filter type=&quot;aspectj&quot; expression=&quot;com.pastis.pq.web.endpoint.*&quot; /&gt;
&lt;!--context:include-filter type=&quot;annotation&quot; expression=&quot;com.pastis.pq.web.&quot;-/--&gt;
&lt;/context:component-scan&gt;
&lt;jpa:repositories base-package=&quot;com.pastis.pq.repositories&quot;/&gt;
&lt;!-- main datasource --&gt;
&lt;bean id=&quot;dataSource&quot;
class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
&lt;property name=&quot;driverClassName&quot; value=&quot;org.h2.Driver&quot; /&gt;
&lt;property name=&quot;url&quot; value=&quot;jdbc:h2:mem:~/test2;DB_CLOSE_DELAY=-1 /&gt;
&lt;property name=&quot;username&quot; value=&quot;sa&quot; /&gt;
&lt;property name=&quot;password&quot; value=&quot;&quot; /&gt;
&lt;/bean&gt;
&lt;!-- transaction management --&gt;
&lt;tx:annotation-driven/&gt;
&lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;
&lt;property name=&quot;entityManagerFactory&quot; ref=&quot;entityManagerFactory&quot; /&gt;
&lt;/bean&gt;
&lt;!-- spring data repositories --&gt;
&lt;jpa:repositories base-package=&quot;com.pastis.pq.repositories&quot;/&gt;
&lt;bean id=&quot;jpaVendorAdapter&quot;
class=&quot;org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter&quot;&gt;
&lt;property name=&quot;database&quot; value=&quot;H2&quot; /&gt;
&lt;property name=&quot;databasePlatform&quot; value=&quot;org.hibernate.dialect.Oracle10gDialect&quot; /&gt;
&lt;/bean&gt;
&lt;bean id=&quot;entityManagerFactory&quot;
class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;
&lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;
&lt;property name=&quot;persistenceUnitName&quot; value=&quot;pastis-entities&quot; /&gt;
&lt;property name=&quot;packagesToScan&quot;&gt;
&lt;array&gt;
&lt;value&gt;com.pastis.pq.model&lt;/value&gt;
&lt;/array&gt;
&lt;/property&gt;
&lt;property name=&quot;jpaVendorAdapter&quot; ref=&quot;jpaVendorAdapter&quot; /&gt;
&lt;property name=&quot;jpaProperties&quot;&gt;
&lt;props&gt;
&lt;prop key=&quot;eclipselink.target-database&quot;&gt;org.eclipse.persistence.platform.database.OraclePlatform&lt;/prop&gt;
&lt;prop key=&quot;eclipselink.target-server&quot;&gt;WebLogic&lt;/prop&gt;
&lt;/props&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;!-- customizable database configuration --&gt;
&lt;bean id=&quot;dataConfig&quot; class=&quot;com.pastis.commons.services.SystemConfig&quot;&gt;
&lt;constructor-arg index=&quot;0&quot; value=&quot;test-config.properties&quot;/&gt;
&lt;constructor-arg index=&quot;1&quot; ref=&quot;dataSource&quot;/&gt;
&lt;/bean&gt;
&lt;/beans&gt;

the console when I run the tests:

2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean &#39;securityManagerController&#39;
2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean &#39;securityManagerController&#39;
2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean &#39;securityManagerController&#39;
2020-10-08 10:46:57,315 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean &#39;securityManagerController&#39;
2020-10-08 10:46:57,317 [DEBUG] org.springframework.beans.factory.annotation.InjectionMetadata - Registered injected element on class [com.pastis.security.controller.SecurityManagerController]: 

答案1

得分: 0

你的初始代码片段是正确的,但是你没有为组件扫描定义正确的包。

如果你要排除的类是这个:

com.pastis.security.controller.SecurityManagerController

而不是这个 XML 片段:

<context:annotation-config />
<context:component-scan base-package="com.pastis.pq" >
    <context:exclude-filter type="assignable" expression="com.pastis.security.controller.SecurityManagerController"/>
</context:component-scan>

<jpa:repositories base-package="com.pastis.pq.repositories"/>

你需要做类似这样的更改:

<context:annotation-config />
<context:component-scan base-package="com.pastis">
    <context:exclude-filter type="assignable" expression="com.pastis.security.controller.SecurityManagerController"/>
</context:component-scan>

<jpa:repositories base-package="com.pastis.pq.repositories"/>

请注意,将包名从 com.pastis.pq 更改为 com.pastis

或者更好的做法是为此目的定义另一个 component-scan 元素:

<context:annotation-config />
<context:component-scan base-package="com.pastis.pq" />
<context:component-scan base-package="com.pastis.security">
    <context:exclude-filter type="assignable" expression="com.pastis.security.controller.SecurityManagerController"/>
</context:component-scan>

<jpa:repositories base-package="com.pastis.pq.repositories"/>

请不要忘记从 &lt;context:component-scan&gt; 元素中删除属性 use-default-filters="false"。如 文档 中所示:

> 您还可以通过在注解上设置 useDefaultFilters=false 或在 &lt;component-scan/&gt; 元素的属性中提供 use-default-filters="false" 来禁用默认过滤器。这实际上会禁用自动检测使用 @Component@Repository@Service@Controller@Configuration 注解的类。

这很可能是你尝试的某种方法中,Spring 无法识别 com.pastis.pq.web.endpoint.* 包中的 bean 的原因。

只要你使用了 &lt;context:component-scan&gt;,可能你可以去掉 &lt;context:annotation-config&gt; 元素。请参阅 这个很棒的回答

更新

在问题的不同更改后,我认为这个 XML 配置应该可以正常工作:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jpa="http://www.springframework.org/schema/data/jpa"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/data/jpa
   http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        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">

    <context:component-scan base-package="com.pastis.pq">
        <context:exclude-filter type="assignable" expression="com.pastis.pq.workflow.web.controller.WorkflowController"/>
        <context:exclude-filter type="assignable" expression="com.pastis.pq.workflow.web.controller.WorkflowAdminController"/>
    </context:component-scan>

    <context:component-scan base-package="com.pastis.security">
        <context:exclude-filter type="assignable" expression="com.pastis.security.controller.SecurityManagerController"/>
    </context:component-scan>

    <jpa:repositories base-package="com.pastis.pq.repositories"/>

    <!-- 主数据源 -->
    <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.h2.Driver" />
        <property name="url" value="jdbc:h2:mem:~/test2;DB_CLOSE_DELAY=-1" />
        <property name="username" value="sa" />
        <property name="password" value="" />
    </bean>

    <!-- 事务管理 -->
    <tx:annotation-driven/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <!-- Spring 数据仓库 -->
    <jpa:repositories base-package="com.pastis.pq.repositories"/>

    <bean id="jpaVendorAdapter"
              class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
        <property name="database" value="H2" />
        <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
    </bean>

    <bean id="entityManagerFactory"
              class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceUnitName" value="pastis-entities" />
        <property name="packagesToScan">
            <array>
              <value>com.pastis.pq.model</value>
            </array>
        </property>
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="jpaProperties">
            <props>
                <prop key="eclipselink.target-database">org.eclipse.persistence.platform.database.OraclePlatform</prop>
                <prop key="eclipselink.target-server">WebLogic</prop>
            </props>
        </property>
    </bean>

    <!-- 可自定义的数据库配置 -->
    <bean id="dataConfig" class="com.pastis.commons.services.SystemConfig">
        <constructor-arg index="0" value="test-config.properties"/>
        <constructor-arg index="1" ref="dataSource"/>
    </bean>

</beans>
英文:

Your initial code snippet is right, but you are not defining the right package for component scanning.

If the class you want to exclude is this:

com.pastis.security.controller.SecurityManagerController

Instead of this XML fragment:

&lt;context:annotation-config /&gt;
&lt;context:component-scan base-package=&quot;com.pastis.pq&quot;  &gt;
    &lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.security.controller.SecurityManagerController&quot;/&gt;
&lt;/context:component-scan&gt;

&lt;jpa:repositories base-package=&quot;com.pastis.pq.repositories&quot;/&gt;

You need something like:

&lt;context:annotation-config /&gt;
&lt;context:component-scan base-package=&quot;com.pastis&quot;&gt;
    &lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.security.controller.SecurityManagerController&quot;/&gt;
&lt;/context:component-scan&gt;

&lt;jpa:repositories base-package=&quot;com.pastis.pq.repositories&quot;/&gt;

Please, notice the change in the package name from com.pastis.pq to com.pastis.

Or better, define another component-scan element for that purpose:

&lt;context:annotation-config /&gt;
&lt;context:component-scan base-package=&quot;com.pastis.pq&quot; /&gt;
&lt;context:component-scan base-package=&quot;com.pastis.security&quot;&gt;
    &lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.security.controller.SecurityManagerController&quot;/&gt;
&lt;/context:component-scan&gt;

&lt;jpa:repositories base-package=&quot;com.pastis.pq.repositories&quot;/&gt;

Please, do not forget to remove the attribute use-default-filters=&quot;false&quot;from the &lt;context:component-scan&gt;element. As indicated in the documentation:

> You can also disable the default filters by setting useDefaultFilters=false on the annotation or providing use-default-filters=&quot;false&quot; as an attribute of the &lt;component-scan/&gt; element. This will in effect disable automatic detection of classes annotated with @Component, @Repository, @Service, @Controller, or @Configuration.

This is very likely the reason why in one of the approaches you tried Spring was unable to identify the beans in your com.pastis.pq.web.endpoint.* package.

As long as you are using &lt;context:component-scan&gt;, probably you can get rid of the &lt;context:annotation-config&gt; element. Please, see this great answer here in stackoverflow.

UPDATE

After the different changes in the question, I think that this XML configuration should work properly:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
        xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
        xmlns:jpa=&quot;http://www.springframework.org/schema/data/jpa&quot;
        xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        xsi:schemaLocation=&quot;http://www.springframework.org/schema/data/jpa
   http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        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&quot;&gt;

    &lt;context:component-scan base-package=&quot;com.pastis.pq&quot;&gt;
        &lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.pq.workflow.web.controller.WorkflowController&quot;/&gt;
        &lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.pq.workflow.web.controller.WorkflowAdminController&quot;/&gt;
    &lt;/context:component-scan&gt;

    &lt;context:component-scan base-package=&quot;com.pastis.security&quot;&gt;
        &lt;context:exclude-filter type=&quot;assignable&quot; expression=&quot;com.pastis.security.controller.SecurityManagerController&quot;/&gt;
    &lt;/context:component-scan&gt;

    &lt;jpa:repositories base-package=&quot;com.pastis.pq.repositories&quot;/&gt;

    &lt;!-- main datasource --&gt;
    &lt;bean id=&quot;dataSource&quot;
            class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;org.h2.Driver&quot; /&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:h2:mem:~/test2;DB_CLOSE_DELAY=-1 /&gt;
        &lt;property name=&quot;username&quot; value=&quot;sa&quot; /&gt;
        &lt;property name=&quot;password&quot; value=&quot;&quot; /&gt;
    &lt;/bean&gt;

    &lt;!-- transaction management --&gt;
    &lt;tx:annotation-driven/&gt;

    &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;
        &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;entityManagerFactory&quot; /&gt;
    &lt;/bean&gt;

    &lt;!-- spring data repositories --&gt;
    &lt;jpa:repositories base-package=&quot;com.pastis.pq.repositories&quot;/&gt;

    &lt;bean id=&quot;jpaVendorAdapter&quot;
              class=&quot;org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter&quot;&gt;

        &lt;property name=&quot;database&quot; value=&quot;H2&quot; /&gt;
        &lt;property name=&quot;databasePlatform&quot; value=&quot;org.hibernate.dialect.Oracle10gDialect&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;entityManagerFactory&quot;
              class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;
        &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;
        &lt;property name=&quot;persistenceUnitName&quot; value=&quot;pastis-entities&quot; /&gt;
        &lt;property name=&quot;packagesToScan&quot;&gt;
            &lt;array&gt;
              &lt;value&gt;com.pastis.pq.model&lt;/value&gt;
            &lt;/array&gt;
        &lt;/property&gt;
        &lt;property name=&quot;jpaVendorAdapter&quot; ref=&quot;jpaVendorAdapter&quot; /&gt;
        &lt;property name=&quot;jpaProperties&quot;&gt;
            &lt;props&gt;
                &lt;prop key=&quot;eclipselink.target-database&quot;&gt;org.eclipse.persistence.platform.database.OraclePlatform&lt;/prop&gt;
                &lt;prop key=&quot;eclipselink.target-server&quot;&gt;WebLogic&lt;/prop&gt;
            &lt;/props&gt;
        &lt;/property&gt;
    &lt;/bean&gt;

    &lt;!-- customizable database configuration --&gt;
    &lt;bean id=&quot;dataConfig&quot; class=&quot;com.pastis.commons.services.SystemConfig&quot;&gt;
        &lt;constructor-arg index=&quot;0&quot; value=&quot;test-config.properties&quot;/&gt;
        &lt;constructor-arg index=&quot;1&quot; ref=&quot;dataSource&quot;/&gt;
    &lt;/bean&gt;

&lt;/beans&gt;

huangapple
  • 本文由 发表于 2020年10月7日 17:32:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/64241198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定