1

I have created following class

@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ApplicationUserInfo implements Serializable {
    private String  user;
    private Integer companynumber;
}

I am ding @Autowire to use this class into my Batch processing which is outside the session. I want to use session scoped bean outside the session so how could I do this? Is there any other way to use that bean.

Please suggest me.

Siddharth
  • 197
  • 1
  • 14
  • What you mean outside of session? Because until the whole flow of the request response is completed it is considered as one session. – Ankit Jan 31 '17 at 06:54
  • When job will schedule we don't know so before scheduling this job I have to access that bean. – Siddharth Jan 31 '17 at 07:02

1 Answers1

1

You can pass the session info as a job parameter on start (where the session exists) and then access the parameter e.g. from reader

JobParameters params = new JobParametersBuilder()
                .addString("user", sessionInfo.getUser())
                .toJobParameters();

...

jobLauncher.run(yourJob, params);

And to get the info in the reader

@Value("#{jobParameters['user']}")
Community
  • 1
  • 1
StanislavL
  • 56,971
  • 9
  • 68
  • 98