Hi,
I have a service and I would like to pass it an argument from atlassian-plugin.xml, such as:
<component key="playsql-service" class="com.playsql.Service"> <property name="param1">configuration.xml</property> </component>
Then the Java class would be:
public class Service { public Service(String param1) { // I expect to receive "configuration.xml" in param1 } }
NB. I can see that they speak of Service Parameters on https://developer.atlassian.com/display/PLUGINFRAMEWORK/Component+Plugin+Module but I couldn't figure how to use them.
Thank you!
Community moderators have prevented the ability to post new answers.
The service-properties element can be used to assign values to certain keys within the atlassian-plugin.xml file; but it isn't the right tool for the job you have.
The service-properties element is used when you want to use the filter attribute of the component-import element.
You should set up your own Spring configuration file as described in the Component Plugin Module documentation:
"If you wish to have more control over how your components are created and configured, you can create your own Spring configuration file, stored in
META-INF/spring
in your plugin jar."
You can use normal Spring xml constructs in your Spring configuration file, which you should place in the META-INF/spring directory under your resources directory.
Got the way, As mentioned by David, there is a need to create Spring Configruation file and should be stored in META-INF/spring folder and that will be loaded automatically.
Here are the steps to do it while developing the Plugin.
1) Create the Spring configruation file under the folder like
\src\main\resources\META-INF\spring\plugin-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <bean id="MyExternalWebService" class="com.company.confluence.services.MyExternalWebService"> <constructor-arg value="url" /> <constructor-arg value="user" /> <constructor-arg value="password" /> </bean> </beans>
2) Now simply inject this object into Target class like
public void setMyExternalWebService(MyExternalWebService myExternalWebService){ this.myExternalWebService = myExternalWebService; }
3) Done, you will get the object of MyExternalWebservice by setter injection. Go ahead and use it.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
+1 to Adrien: How do you inject the value as constructor injection. please provide the example
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.