我知道在Spring中将请求作用域bean注入到单例bean中是可能的,所以我知道我正在尝试做的事情将会起作用,我只是想知道是否有一种方法可以更简洁地表达它,而不需要这么多额外的不必要的类定义。我是Spring注解的新手,所以可能有一个我不知道的注解。
我有一个抽象类,它在我的应用程序中可能会被扩展100次,成为不同的单例spring bean。以这个类定义为例:
/** The abstract class with a field that needs to be request-specific **/
public abstract class AbstractSingletonBea
我正在使用Vaadin Spring1.0.0,并试图弄清楚如何将仅在UI范围内(当用户打开页面时)可用的bean注入到经典的Spring @Component bean中。简单地说,让我们拥有类:
@Component
public class A {
@Inject
private IB b;
}
@UIScope
@SpringComponent
public class B implements IB {
}
显然在启动过程中:
Caused by: java.lang.IllegalStateException: No VaadinSession bound to
这个例子只是一个虚拟的例子,它展示了我正在处理的问题,所以不要在解决具体问题的其他方法上太过纠结。我的问题是更多地了解解决春季问题的适当技巧
假设我有一个托管bean Info
@Component
public class Info {
private final String activeProfile;
private final Instant timestamp;
public Info(@Value("${spring.profiles.active}") String activeProfile) {
this.activeProfile =
我正在从一个作业工厂类中获取Error creating bean with name 'scopedTarget.scopedTarget.processVlsCasesJob': Scope 'job' 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。工厂是在正确的作业/步骤作用域中从主应用程序启动期间调用的bean创建作业和步骤bean的位置。
默认情况下,Spring创建的Bean是单例的。它们是线程安全的,因为它们是无状态的。当我们想让Spring创建一个有状态的Bean时,我们需要使用prototype作用域来定义Bean。我们需要为它们处理线程安全问题。所有无状态bean在被原型Bean注入时都会受到污染。所以,我不能想象我们可以在哪里使用原型作用域。你能给出一些我们可以/需要使用prototype Spring Bean的典型场景吗?另外,我们如何避免其他单例bean上的有状态污染?
我尝试Spring和泽西岛integration.But,我对作用域感到困惑。对于spring,默认范围是Singleton。对于泽西,默认范围是请求。
例如:
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
// The Java class will be hosted at the URI path "/myresource"
@Path("/myresource")
@Component
@