界面
package org.employee.employee.core.admin;
import org.apache.sling.api.resource.ResourceResolver;
public interface CustomerService {
public String getCustomerData();
}
服务类 ==> 获取 resolverFactory null
package org.employee.employee.core.admin;
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype = true, immediate = true)
@Service
public class CustomerServiceImpl implements CustomerService {
protected final Logger log = LoggerFactory.getLogger(this.getClass());
@Reference
private ResourceResolverFactory resolverFactory;
public String getCustomerData() {
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "CustomerService");
ResourceResolver resolver = null;
try {
resolver = resolverFactory.getServiceResourceResolver(param);
System.out.println(resolver);
} catch (LoginException loginExcp) {
log.error("Exception while getting resource resolver." + loginExcp);
}
return resolver.toString();
}
}
服务组件显示状态 => 活动
用户映射器