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

Support @Profile + @PostConstruct/@PreDestroy [SPR-12433] #16902

Closed
spring-projects-issues opened this issue Nov 13, 2014 · 7 comments
Closed

Support @Profile + @PostConstruct/@PreDestroy [SPR-12433] #16902

spring-projects-issues opened this issue Nov 13, 2014 · 7 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 13, 2014

Mordechai Tamam opened SPR-12433 and commented

I have a use case that I need a custom bean initialization for each profile, there fore I would like to have the ability to control the @PostConstruct initialization methods.


No further details from SPR-12433

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 14, 2014

Stéphane Nicoll commented

What are you after exactly? a @PostConstruct annotated method with @Profile that would be called only if that profile is active?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 14, 2014

Mordechai Tamam commented

Yes, exactly.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 14, 2014

Stéphane Nicoll commented

Are you aware you can only have one @PostConstruct method in a given class? From the javadoc

Only one method can be annotated with this annotation.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 14, 2014

Mordechai Tamam commented

Now that you mentioned it, I do.
It's a bit confusing, since I placed two methods, annotated with @PostConstruct, and they are both invoked (using spring - 4.0.7, if it matters).

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 14, 2014

Stéphane Nicoll commented

Interesting, I wasn't aware our support was more relaxed. Juergen Hoeller, thoughts?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 14, 2018

ch ki commented

What about

@PreDestoy

I would like to do something like this:

@PreDestroy
@Profile("develop")
private void cleanUpKafka() {
    clientService.deleteAllTopics();
}
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 12, 2019

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants