Skip to content

Can configure @EnablePublisher(proxyTargetClass=true) #2695

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

Closed
italktothewind opened this issue Jan 14, 2019 · 3 comments · Fixed by #2701
Closed

Can configure @EnablePublisher(proxyTargetClass=true) #2695

italktothewind opened this issue Jan 14, 2019 · 3 comments · Fixed by #2701
Assignees
Milestone

Comments

@italktothewind
Copy link

italktothewind commented Jan 14, 2019

Enhancement

Problem: As discussed in https://stackoverflow.com/questions/54150939/spring-cloud-stream-and-publisher-annotation-compatiblity/54151130, services using @Publisher annotation can't be injected using @Autowire

Possible solution: using an annotation like @EnablePublisher(proxyTargetClass=true). Other proxy implementations of Spring like @Cacheable or @Async use this flag.

@artembilan artembilan added this to the 5.1.3 milestone Jan 14, 2019
@artembilan
Copy link
Member

Please, make yourself familiar with GitHub comments formatting, especially about code snippets: https://help.github.com/articles/basic-writing-and-formatting-syntax/

You are welcome to come back to us with Contribution: https://github.com/spring-projects/spring-integration/blob/master/CONTRIBUTING.adoc

@garyrussell
Copy link
Contributor

Until the annotation is fixed, I added a work around here.

@artembilan
Copy link
Member

Another issue is like this: https://stackoverflow.com/questions/54207305/spring-cloud-stream-streamlistener-processing-messages-twice.

To reconsider the PublisherAnnotationBeanPostProcessor bean as really a singleton and don't depend on particular name.
However at the same time end-user may declare several of them, so maybe it is better consider do not apply the PublisherAnnotationAdvisor to the same bean more than once.

@artembilan artembilan self-assigned this Jan 16, 2019
artembilan added a commit to artembilan/spring-integration that referenced this issue Jan 16, 2019
Fixes spring-projects#2695

To configure a `proxyTargetClass=true` we need declare a
`PublisherAnnotationBeanPostProcessor` bean manually, but that may cause
a confuse when `@EnablePublisher` is still present.
So, target service is proxied twice

* Expose `proxyTargetClass` and `order` into the `@EnablePublisher`
and `<enable-publisher>`
* Refactor `PublisherAnnotationBeanPostProcessor` to extend an
`AbstractBeanFactoryAwareAdvisingPostProcessor` to avoid AOP boilerplate
code altogether
* Add assertion into the `PublisherAnnotationBeanPostProcessor` to be
sure that only one of its instance is present in the application context
garyrussell pushed a commit that referenced this issue Jan 17, 2019
* GH-2695: Add proxy option to @EnablePublisher

Fixes #2695

To configure a `proxyTargetClass=true` we need declare a
`PublisherAnnotationBeanPostProcessor` bean manually, but that may cause
a confuse when `@EnablePublisher` is still present.
So, target service is proxied twice

* Expose `proxyTargetClass` and `order` into the `@EnablePublisher`
and `<enable-publisher>`
* Refactor `PublisherAnnotationBeanPostProcessor` to extend an
`AbstractBeanFactoryAwareAdvisingPostProcessor` to avoid AOP boilerplate
code altogether
* Add assertion into the `PublisherAnnotationBeanPostProcessor` to be
sure that only one of its instance is present in the application context

* * Polishing error message and Docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants