0

セッションスコープとして宣言されている Bean があります。他の Bean (デフォルトではシングルトン) で使用するには、構成で aop を有効にする必要がありました。

設定

<?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:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc 
         http://www.springframework.org/schema/mvc/spring-mvc-3.2.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/jdbc
         http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
         http://www.springframework.org/schema/jee
         http://www.springframework.org/schema/jee/spring-jee.xsd
         http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop.xsd
         ">
    ...
    <bean id="localeResolver" class="com.my.pack.MySessionLocaleResolver" scope="session">
        <property name="defaultLocale" value="en" />
        <aop:scoped-proxy/>
    </bean>

WindowsデスクトップコンピューターでEclipseから起動している間、宣言されているようにうまく機能します。しかし、テスト用の Linux 環境で公開すると、どういうわけか aop が無視され、エラーがスローされます。

Linux 環境での例外

11:09:24,928 ERROR {localhost-startStop-1} [org.springframework.web.servlet.FrameworkServlet:initServletBean] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.localeResolver': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is 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.
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:343)

ログ ファイルに追加のエラーはありません。Web アプリのログにも、catalina.out にもありません。Tomcat 7.0.42および「CentOSリリース6.5」でSpring 3.2.4を使用しています。

4

1 に答える 1

0

これらのエラー メッセージを注意深く読んでください。失敗した理由が常に含まれています。

この場合:

Scope 'session' is not active for the current thread

これは、Bean が要求されたときにアクティブな HTTP セッションがないことを意味します。

于 2014-03-07T13:15:23.617 に答える