Say I have an interface, like WidgetGroker, and I have several implementations of WidgetGroker. I want my Component to have a class layout like this:
class JiraEventListener { private Collection<WidgetGroker> grokers; public JiraEventListener(Collection<WidgetGroker> theGrokers) { this.grokers = theGrokers; } @EventListener public void eventListener(...) { .... } // ... }
I tried this and spring exploded with "no unique bean" errors or "no matching ctor" or whatever. Is there a way to do this? I have a <component> thing in my atlassian-plugin.xml for each implementation of WidgetGroker as well as a proper listener definition for JiraEventListener.
Thanks!
-Carl
EDIT: formatting fail =(
You can do that by adding a Spring configuration file in resources/META-INF/spring/plugin-components.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd" default-autowire="autodetect"> <bean id="jiraEventListener" class="com.company.product.package.JiraEventListener"> <constructor-arg> <list> <ref bean="groker1"/> <ref bean="groker2"/> <ref bean="groker3"/> </list> </constructor-arg> </bean> </beans>
Awesome! I will try this out and accept your answer when I get it working =D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Carl, let us know if this answer works for you :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry it took me so long to find time to test this answer - it totally works for me! Thanks very much! =D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
BTW, if your constructor takes multiple arguments, you probably have to list them too - so my actual code looks something like this:
<bean id="blah"> <constructor-arg ref="arg1"/> <constructor-arg ref="arg1"/> <constructor-arg ref="arg2"/> <constructor-arg> <list> <ref bean="arg3-item1"/> <ref bean="arg3-item2"/> </list> </constructor-arg> <constructor-arg ref="arg4"/> <!-- .... --> </bean>
EDIT: fixed the code - recently realized it wasn't quite right.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.