当我在osgi包中的服务类中有以下代码时,以下异常就是抛出我的cq页面。 任何想法?
org.apache.sling.api.scripting.ScriptEvaluationException:javax.servlet.ServletException:java.lang.NoClassDefFoundError
将使用Sling.getService()api
从JSP调用service.getFund()@Component
@Service(ProductService.class)
public class ProductServiceImpl implements ProductService {
public Fund getFund() {
Product[] origList = resultProducts();
Product dumP = copyCustom(origList[0]);
List<Product> pp = new ArrayList<Product>();
pp.addAll(new ArrayList<Product>(Arrays.asList(origList)));
pp.add(dumP);
filteredProducts = (Product[])pp.toArray();
}
@SuppressWarnings("unchecked")
private <T> T copyCustom(T entity) throws IllegalAccessException, InstantiationException {
Class<?> clazz = entity.getClass();
T newEntity = (T) entity.getClass().newInstance();
while (clazz != null) {
copyFields(entity, newEntity, clazz);
clazz = clazz.getSuperclass();
}
return newEntity;
}
private <T> T copyFields(T entity, T newEntity, Class<?> clazz) throws IllegalAccessException {
List<Field> fields = new ArrayList<>();
for (Field field : clazz.getDeclaredFields()) {
fields.add(field);
}
for (Field field : fields) {
field.setAccessible(true);
field.set(newEntity, field.get(entity));
}
return newEntity;
}
}