0

我有一个 Web 应用程序,我在其中定义了 2 个 bean 1 和一个单例范围,一个具有请求范围。我需要单例 bean 中的请求范围 bean。

所以我结束了这个

<bean id="routingDataSource" class="org.ai2l.ifsr.service.multiTenants.RoutingDataSource" scope="request">
    <aop:scoped-proxy/>
    <property name="targetDataSources" value="#{tenantSpecificDependencyFactory.tenantIdToDataSource}"/>
    <!-- <property name="defaultTargetDataSource" ref="parentDataSource"/>         -->
</bean>


<bean id="entityManagerFactory"   class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="ifsrPU"/>
    <property name="dataSource" ref="routingDataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="databasePlatform" value="${hibernate.dialect}"/>
        </bean>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.ejb.naming_strategy">
              org.hibernate.cfg.ImprovedNamingStrategy
            </prop>
        </props>
    </property>

</bean>

你会注意到我已经使用了,<aop:scoped-proxy/>但它不起作用。我也试过

  <listener>
<listener-class>
  org.springframework.web.context.request.RequestContextListener
</listener-class>

在我的 web.xml 里面。但这些都不起作用。

我仍然收到此错误

Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

有谁知道为什么会这样??

4

0 回答 0