1
votes

I have a problem with one of my beans. I have a bean, which has a singleton scope and second bean which has session scope.

I'm using java based config in my spring app, I added proxy mode to my session scope bean, but it throws exception when I'm tryign to use that (session scoped) bean:

Method threw 'org.springframework.beans.factory.BeanCreationException' exception. Cannot evaluate my-bean-full-name$$EnhanceBySpringCGLIB#ID.toString()

From what I have read here http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-factory-scopes-other-injection-proxies

I thought that only thing which I have to do is to add

@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)

to my bean class (which also has @Component annotation and it is scanned by Spring)

1
share your code snippet?Chowdappa
does the session scoped bean implement an interface? If not let it implement and perhaps make it serializableHank Lapidez
Thanks for the response. @HankLapidez I will check your suggestionMa Kro
@CHowdappaM What snippet? The only thing which i use here is the Scope annotation. Tehn I use Autwired on field to inject my bean. I also use componentScan annotation to scan package with my bean. I don't use any code more to reach my goalMa Kro
@HankLapidez it didn't helped. I left annotations on implementation classMa Kro

1 Answers

2
votes

The thing which I was missing was this line in my web app initializer:

    servletContext.addListener(new RequestContextListener());

After that, bean has been injected