on 2023 Jan 24 4:12 PM
I have written some util functions which use ConfigurationService to fetch string values. (In src of a custom extension)
To autowire the ConfigurationSerivce outside of a controller my understanding is you need to tell spring to pick up the class through an annotation or through adding it to a bean.
Both ways I have tried have resulted in a error: Cannot invoke \"de.hybris.platform.servicelayer.config.ConfigurationService.getConfiguration()\" because \"this.configurationService\" is null
Does anyone know if my logic is off in getting the DI to work?
Request clarification before answering.
<context:component-scan base-package="your.package.name.of.util.class"/>
Example:
public class MyClass {
private ConfigurationService configurationService;
public String getMyValue() {
return getConfigurationService().getConfiguration().getString("example.value", "default value");
}
public ConfigurationService getConfigurationService() {
return configurationService;
}
/**
* Spring injects the value with this setter!
public void setConfigurationService(ConfigurationService configurationService) {
this.configurationService = configurationService;
}
<bean id="myClass" class="com.example.MyClass">
<property name="configurationService" ref="configurationService" />
</bean>
If none of the above solutions work, please provide more details about your project setup, including the versions of SAP Commerce that you are using, and the specific packages and classes that you are importing and annotating. This will help to troubleshoot the issue more effectively.
Spring Framework in SAP Commerce:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.