我在Karaf中使用cxf dosgi暴露了jax-rs服务。我正在尝试使用hibernate提供程序添加bean验证。
我添加了以下意图来启用hibernate提供程序:
@SuppressWarnings("serial")
class BarChart2 extends JPanel {
private static final double BAR_WIDTH = 0.90;
private int prefW;
private int prefH;
private static final Color BAR_COLOR = Color.RED;
private int[] data;
private int maxValue;
public BarChart2(int[] data, int maxValue, int prefW, int prefH) {
setData(data, maxValue);
this.prefW = prefW;
this.prefH = prefH;
}
public final void setData(int[] data, int maxValue) {
this.data = data;
this.maxValue = maxValue;
repaint();
}
public int[] getData() {
return data;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(BAR_COLOR);
// simple algebraic calculations on where to place the bars
double denom = data.length + 1 - BAR_WIDTH;
int barWidth = (int) ((getWidth() * BAR_WIDTH) / denom);
for (int i = 0; i < data.length; i++) {
int x = (int) (getWidth() * (i + 1 - BAR_WIDTH) / denom);
int height = (int) (getHeight() * data[i] / (double) maxValue);
int y = (int) (getHeight() - height);
g.fillRect(x, y, barWidth, height);
}
}
@Override
public Dimension getPreferredSize() {
if (isPreferredSizeSet()) {
return super.getPreferredSize();
}
return new Dimension(prefW, prefH);
}
}
}
但我在底部得到例外。我添加了包含丢失类的包(包装):
@Component(immediate = true, property = "org.apache.cxf.dosgi.IntentName=bean-validation")
public class BeanValidationIntent implements Callable<List<Object>> {
@Override
public List<Object> call() throws Exception {
List<Object> list = new ArrayList<Object>();
BeanValidationFeature beanValidationFeature = new BeanValidationFeature();
beanValidationFeature.setProvider(new BeanValidationProvider(new HibernateValidationProviderResolver()));
list.add(beanValidationFeature);
return list;
}
这仍然无法解决问题。
我正在使用karaf 4.0.8
如果您有任何想法请分享!谢谢!
install -s wrap:mvn:com.sun.el/el-ri/1.0
答案 0 :(得分:0)
EL ExpressionFactory初始化有点儿错误:它使用TCCL而不是使用自己的类加载器,我们的Karaf功能不会导入com.sun.el,因为它不是必需的。
我们在HV中引入了externalClassLoader()方法,以解决这个问题。
了解我们如何在OSGi集成测试中使用它: https://github.com/hibernate/hibernate-validator/blob/5.4/osgi/integrationtest/src/test/java/org/hibernate/validator/osgi/integrationtest/OsgiIntegrationTest.java#L139
(请注意,在5.4中,您还需要providerResolver()调用 - 此限制将在即将推出的6.0中删除。