How do I stop spring from injecting Properties.class into my plugin?

seank33f3 June 20, 2019

We have a plugin that worked fine on Jira 7 but began failing to start on Jira 8.  I narrowed down the failure to a class that has a Properties.class being injected into it by Jira; presumably, by the Spring framework.  This application is designed to be agnostic of Jira and operate in a number of our tools.  For that reason, it does not import anything specific to Jira or any other tool.  It does not import the Spring framework, but still receives the false class being injected into it.

The usual way this class gets initialized is through it's own no-arg constructor, which calls private methods to send a Properties file that has been read off the file system, into a constructor which accepts the Properties file.

Roughly, the class is (It's the properties file in the second constructor that is being injected):

public ConfigClass() {
    this(buildPropertiesFile());
}

public ConfigClass(Properties config) {
    fieldVar1 = config.getProperty("blah");
    etc...
}

Is it possible to stop the Properties file from being injected without having to import the spring framework?

It's written this way for improved test-ability, which I'm trying to preserve.  I've confirmed it works if I get rid of the constructor accepting the Properties.class and just initialize fully through the no-arg constructor, but this breaks most of it's tests because we then can't mock out the incoming properties.  At least not cleanly.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events