Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WARN: @Bean method StepScopeConfiguration.stepScope is non-static [BATCH-2161] #1434

Closed
spring-projects-issues opened this issue Jan 9, 2014 · 17 comments
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" has: votes Issues that have votes in: core type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Jean-Pierre Bergamin opened BATCH-2161 and commented

When using Java based configuration and the @StepScope annotation you get the following warning in the logs, when starting the application context:

WARN ConfigurationClassEnhancer:277 - @Bean method StepScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean Javadoc for complete details

A short glimpse at the StepScopeConfiguration class lets me think that the stepScope bean really can be declared static.

See also the last chapter "BeanFactoryPostProcessor-returning @Bean methods" in the @Bean api documentation.


Affects: 3.0.0

Issue Links:

  • BATCH-2574 A WARN log has been outputted for @Bean method that support custom scope
    ("is duplicated by")

Backported to: 3.0.9

16 votes, 23 watchers

@spring-projects-issues
Copy link
Collaborator Author

Guilherme Trein commented

The same happens with ScopeConfiguration.jobScope.

@spring-projects-issues
Copy link
Collaborator Author

Diego Magalhaes commented

+bump, still happening. Is it safe to just add the static keyword to both?

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

Are there any side effects. I see a comment in the source code indicating that it was intentionally non-static. So what's the problem?

@spring-projects-issues
Copy link
Collaborator Author

matt crowe commented

I see the same message in the logs. I am not setting the StepScope. I am using @EnableBatchProcessing and @Configuration .
[main] WARN : @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details

@spring-projects-issues
Copy link
Collaborator Author

Michael Minella commented

matt crowe, @EnableBatchProcessing creates a step scope for you. That's why you're seeing the warning.

@spring-projects-issues
Copy link
Collaborator Author

matt crowe commented

Thanks for the reply. I actually was aware that the StepScope setup was being done for me as part of that annotation. But should the warning just be ignored? i.e. is it more of an info message, or is my configuration not in an optimal state. (My Job, with 2 steps, seems to work fine. It is called once per day.)

@spring-projects-issues
Copy link
Collaborator Author

Michael Minella commented

Yes. It should be ignored. It comes from Spring Core (not Spring Batch). Your application is doing nothing wrong, Batch just doesn't have a way to suppress that warning.

@spring-projects-issues
Copy link
Collaborator Author

Jean-Pierre Bergamin commented

Why not declaring the stepScope bean static?

@spring-projects-issues
Copy link
Collaborator Author

matt crowe commented

Michael, Thanks for letting me know that the warn is to be expected in this case. Jean-Pierre, I don't declare the StepScope, as it is configured as part of @EnableBatchProcessing.

@spring-projects-issues
Copy link
Collaborator Author

Diego Magalhaes commented

@matt crowe, I'm currently using

<logger name="org.springframework.context.annotation.ConfigurationClassEnhancer" level="ERROR" />

on all my spring batch logback.xml files to avoid this message.

@spring-projects-issues
Copy link
Collaborator Author

matt crowe commented

@Diego, Nice. I will add. Hate having junk in the logs that might cause confusion later on.

@spring-projects-issues
Copy link
Collaborator Author

Philippe Marschall commented

pull request:
#386

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wingert commented

Any news on this? @Michael Minella: do you intend to merge Philippe's pull request?

@spring-projects-issues
Copy link
Collaborator Author

Michael Minella commented

There is a comment in the code that we did not want the methods to be static. The warning this produces is not a Spring Batch one, it's Spring Core which does not apply to the use case implemented here (We are not processing @Autowired, @Resource, or @PostConstruct annotations). I'm closing this PR as works as designed. If this is an issue with the community, maybe we should take it up with the Spring Framework team to get that warning moved to a debug message.

@spring-projects-issues
Copy link
Collaborator Author

Sander Verhagen commented

People are clearly trying to reduce errors and warnings in their log files, and out of the box this seems to be working with Spring (Boot) in such a way that a warning comes up. I see the comment you're referring to, and I wouldn't want static fields in ScopeConfiguration either, but can't stepScope() and jobScope() just return a new StepScope() resp. new JobScope()? Or would there be another solution that works out of the box?

@spring-projects-issues
Copy link
Collaborator Author

Philippe Marschall commented

@sverhagen a fix has been merged into 3.0.9 and 4.0.1, the resolution "Works as Designed" does not reflect the current state

@spring-projects-issues
Copy link
Collaborator Author

Mahmoud Ben Hassine commented

The status of the issue was updated to "Fixed". This improvement will be part of next release.

@spring-projects-issues spring-projects-issues added has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" type: enhancement in: core has: votes Issues that have votes labels Dec 16, 2019
@spring-projects-issues spring-projects-issues added this to the 4.0.1 milestone Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" has: votes Issues that have votes in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant