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

Comment From: spring-projects-issues

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?

Comment From: spring-projects-issues

Mordechai Tamam commented

Yes, exactly.

Comment From: spring-projects-issues

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.

Comment From: spring-projects-issues

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).

Comment From: spring-projects-issues

Stéphane Nicoll commented

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

Comment From: spring-projects-issues

ch ki commented

What about

@PreDestoy

I would like to do something like this:

@PreDestroy
@Profile("develop")
private void cleanUpKafka() {
    clientService.deleteAllTopics();
}

Comment From: spring-projects-issues

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

Comment From: marwin1991

Would be nice to have this feature