Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Springbean中使用会话范围_Java_Spring_Jsf 2 - Fatal编程技术网

Java 在Springbean中使用会话范围

Java 在Springbean中使用会话范围,java,spring,jsf-2,Java,Spring,Jsf 2,我使用JSF2作为视图,使用Spring作为业务逻辑。我试图使用注释(@scope(“session”)将会话范围设置为我的一个Springbean,但我遇到了以下异常: SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handleFiles': Injection of aut

我使用JSF2作为视图,使用Spring作为业务逻辑。我试图使用注释(@scope(“session”)将会话范围设置为我的一个Springbean,但我遇到了以下异常:

    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handleFiles': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private creazione.util.FTPOperations creazione.components.HandleOldFiles.operations; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'ftpOperations': 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.
我知道RequestContextListener。它在我的web.xml中。我还添加了RequestContextFilter:

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

    <filter>
        <filter-name>requestContextFilter</filter-name>
        <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>requestContextFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

org.springframework.web.context.ContextLoaderListener
org.springframework.web.context.request.RequestContextListener
requestContextFilter
org.springframework.web.filter.RequestContextFilter
requestContextFilter
/*
要求
包括
向前地
似乎什么都不管用。我做错了什么?
谢谢大家!

尝试使用aop:scoped proxy将必须注入的bean定义为会话

<bean id="ftpOperations" class="..." scope="session">
    <aop:scoped-proxy/>
</bean>

如果相关名称空间尚未出现,请添加该名称空间:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
    ...
xsi:schemaLocation="
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        ...

如果使用基于注释的配置,只需在主配置xml中更改此标记:

<context:component-scan base-package="my.package"/>
这是我的工作。 详情如下:

另外,如果您要通过上下文xml配置创建bean,下面是另一个示例:

<bean id="somebean" class="com.package.beans" scope="session">
    <aop:scoped-proxy/>
</bean>


是的,但我正在使用注释。我有很多SpringBean要在applicationContext.xml中编写。是否有与之等效的注释?试着看看这个问题仍然不太有效…我添加了@Scope(value=“session”,proxyMode=ScopedProxyMode.INTERFACES),我为每个Springbean重构了一个接口,但现在自动连线不再识别我的bean…错误消息是什么?请记住,您可以指定一个限定符来帮助连接过程,例如:@Autowired@Qualifier(“beanName”)是的,我使用了该限定符;异常是:由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到依赖项类型为[creazione.util.FTPOperations]的匹配bean:至少需要1个符合此依赖项autowire候选项条件的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true),@org.springframework.beans.factory.annotation.Qualifier(value=ftpOperations)}这对我不起作用。我得到相同错误的三种方法都无法连接。它不是自动连接的原因有很多——范围设置中断,缺少cglib it类路径(如果您是没有接口的自动连接)。有关详细信息,请参阅错误消息。
@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
<bean id="somebean" class="com.package.beans" scope="session">
    <aop:scoped-proxy/>
</bean>