The Default Configuration works in the following Order to get Configuration-Values:
The First found value will be returned.
If no Value where Found, NULL will be returned.
The complete default configuration can be found there: ./XMLSchema/defaultsettings4j.xml
The XML Schema Definition can be found there: ./XMLSchema/settings4j.dtd
Simply put your own settings4j.xml into the root-classpath or configure it manual in Java.
settings4j.xml (accurate to log4j.xml) must be availabel inside the classpath.
An Example code to add a custom Connector could looks like the following:
public void initSettings4j() {
String connectorName = "myConnector";
Connector connector = Settings4j.getSettings().getConnector(connectorName);
if (connector == null) {
MyConnector myConnector = new MyConnector(...);
// add the connecter after the last SystemPropertyConnector or add it as first connector.
Settings4j.getSettings().addConnector(myConnector, //
ConnectorPositions.firstValid(//
ConnectorPositions.afterLast(SystemPropertyConnector.class), //
ConnectorPositions.atFirst() // if no SystemPropertyConnector is configured.
)//
);
}
}
In case you are not happy to place your settings4j.xml into the classpath, You can configure Settings4j from any URL you want:
String configLocation = "file:.../mySettings4j.xml"; URL url = new URL(configLocation); Settings4j.getSettingsRepository().resetConfiguration(); DOMConfigurator.configure(url, Settings4j.getSettingsRepository());
If you use the Spring-Placeholder for Settings4j, you must use a depends-on attribute to be sure that the initialization runs first:
<beans> <bean class="org.settings4j.helper.spring.Settings4jPlaceholderConfigurer" depends-on="initSettings4j"/> <!-- InitSettings4j.initSettings4j() will add the custom converter to the Settings4j instance. --> <bean id="initSettings4j" class="com.myProject.InitSettings4j" init-method="initSettings4j"/> </beans>