gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:03:16 32 4
gpt4 key购买 nike

我有一个被声明为 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com