linux - Spring aop作用域代理在Linux安装上不起作用

标签 linux spring aop session-scope

我有一个被声明为 session 范围的 bean。我必须在我的配置中启用 aop 才能在其他 bean 中使用它(默认为单例)。

配置

<?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>

当我从 eclipse 启动它时,在我的 Windows 台式计算机上,它工作得很好,正如它所声明的那样。 但是,当我在我的测试 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)

日志文件中没有其他错误。也不在网络应用程序日志中,也不在 catalina.out 中。 我在 tomcat 7.0.42 和“CentOS 版本 6.5”上使用 spring 3.2.4。

最佳答案

仔细阅读这些错误消息,它们总是包含失败的原因。

在这种情况下:

Scope 'session' is not active for the current thread

这意味着当请求 bean 时您没有事件的 HTTP session 。

关于linux - Spring aop作用域代理在Linux安装上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22250937/

相关文章:

java.lang.ClassNotFoundException : org. springframework.web.context.request.RequestContextListener 问题

oracle - 如何在 Hibernate Spring 中访问特定模式?

Spring Boot + Primefaces - "Unrecognized Content Type"异常

java - 在 aspect 中读取注释属性

java - 从Java进程访问子进程控制终端

linux - 如何排除文件及其上下行中的匹配模式?

java - 如何在AspectJ中提供动态切入点?

java - 第二个带注释的方面未被调用

linux - 如何使用 Gnuplot 4.6 和 AIX 7.2 修复 "Could not find/open font when opening font arial..."和模糊的 png?

c++ - 错误错误: ‘void*’ is not a pointer-to-object type