简体   繁体   中英

Spring request-scoped bean - all fields null/empty

I am creating a class with two request-scoped beans. The beans classes are annotated with:

@Component
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class RequestScopedBean1 {
  // stuff
}

and their declaration as field in my class is:

@Resource
private RequestScopedBean1 requestScopedBean1

@Resource
private RequestScopedBean2 requestScopedBean2

This system has been used all over the code base I am working on with no problems. However, in my class, one of the injected beans (not both, only one!) has all its fields null/empty.

I am aware that simply looking at a request-scoped bean's fields in debug mode will normally show that they are all null because of how Spring's manages such beans with proxies. I am also aware that fields should be accessed with getters and setters, not directly, for the same reason. However, this bean still appears null/empty when using the Evaluate Expression function in intelliJ.

My class and each bean class are in different projects. The working bean is in the core project. The broken bean is in a project with a dependency on the core project, and my class is in a project with a dependency on the broken bean's project.

Please let me know if you need any more information to help me out here!

Edit A brief description of my XML config files:

There are 4 relevant projects, lets call them 'core', 'web', 'common' and 'specific'. Each has its own corresponding application-context.xml The application is deployed from a .war file built from the 'specific' project. In the tag for the 'specific' web.xml the application contexts for 'web' and 'specific' are imported. The first line of the 'specific' application-context.xml imports the application-context for 'common', which is where my new class resides. The first line of 'web' application-context.xml imports the 'core' application-context. The working request-scoped bean resides in 'core'; the broken one in 'web'. I hope that is clear - let me know if not! Would any other info be useful?

It could be that the access specifier for the setters and getters you are trying to access in the class are not specified (ie Default). Try changing it to public and see.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM