Reputation: 1
I can't access to alfresco-global.properties values dynamically although I read this post: Accessing values from Alfresco's alfresco-global.properties file
Here is my conf:
service-context.xml
<bean id="AccesGlobalPropertiesService" class="com.package.ksc.services.AccesGlobalPropertiesService">
<property name="properties">
<ref bean="global-properties"/>
</property>
</bean>
AccesGlobalPropertiesService.java
import org.springframework.stereotype.Service;
import java.util.Properties;
@Service
public class AccesGlobalPropertiesService {
public Properties properties;
public void setProperties(Properties properties) {
this.properties = properties;
}
public Properties getProperties() {
return properties;
}
}
Worker.java
public abstract class ClassifierServiceCommon {
private AccesGlobalProperties accesGlobalProperties;
private Properties properties;
/* Constructor */
protected Worker(accesGlobalProperties) {
this.accesGlobalProperties= accesGlobalProperties;
}
...
protected Boolean propAcces() {
accesGlobalProperties.properties.getProperty("myPropKey");
...
}
}
I get a NullPointerException when I call getProperty("myPropKey") ...
What's wrong please? Thanks
Upvotes: 0
Views: 615
Reputation: 558
It seems like you made the mistake of defining two beans with different ID-s:
properties
field is correctly set.@Service
annotation), its ID is implicitly set to "accesGlobalPropertiesService". Its properties
field is not set, because a @Resource
or @Autowired
annotation is missing for that field (see e. g. this question on how to use them).And then you most probably use the second (incomplete) one from your ClassifierServiceCommon
class. (You didn't specify how you get the bean there.)
Upvotes: 1
Reputation: 171
You have to initialize the variable (You don't seem to do it). You need to setProperty() before you getProperty(). As long as you don't initialize properties in the AccesGlobalPropertiesService class, your getProperty() will return null.
I don't know if that's what you're trying to do here :
protected Boolean propAcces(){
accesGlobalProperties.properties.getProperty("myPropKey");
...
}
If that is the case, you should change getProperty for setProperty.
I hope this helps you :)
Upvotes: 0