这是部分代码
Constructor<ExternalAttachmentProvider> constructor=ExternalAttachmentProvider.class.getConstructor(Bus.class);(出错位置)
ExternalAttachmentProvider eap =(ExternalAttachmentProvider)constructor.newInstance(bus);
ExternalAttachmentProvider 的部分源码
public class ExternalAttachmentProvider extends AbstractPolicyProvider
implements PolicyProvider {
private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ExternalAttachmentProvider.class);
// Use a Resource object here instead of a String so that the resource can be resolved when
// this bean is created
private Resource location;
private Collection<PolicyAttachment> attachments;
ExternalAttachmentProvider() {
}
ExternalAttachmentProvider(Bus b) {
super(b);
}
。
报错为
Exception in thread "main" java.lang.NoSuchMethodException: org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider.<init>(org.apache.cxf.Bus)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at demo.ws_policy.server.Server.<init>(Server.java:59)
at demo.ws_policy.server.Server.main(Server.java:97)
不知道这是错误?请各位指教
Constructor<ExternalAttachmentProvider> constructor=ExternalAttachmentProvider.class.getConstructor(Bus.class);(出错位置)
ExternalAttachmentProvider eap =(ExternalAttachmentProvider)constructor.newInstance(bus);
ExternalAttachmentProvider 的部分源码
public class ExternalAttachmentProvider extends AbstractPolicyProvider
implements PolicyProvider {
private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ExternalAttachmentProvider.class);
// Use a Resource object here instead of a String so that the resource can be resolved when
// this bean is created
private Resource location;
private Collection<PolicyAttachment> attachments;
ExternalAttachmentProvider() {
}
ExternalAttachmentProvider(Bus b) {
super(b);
}
。
报错为
Exception in thread "main" java.lang.NoSuchMethodException: org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider.<init>(org.apache.cxf.Bus)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at demo.ws_policy.server.Server.<init>(Server.java:59)
at demo.ws_policy.server.Server.main(Server.java:97)
不知道这是错误?请各位指教
是否引用的jar不是最新的或不是合适的
ExternalAttachmentProvider这个类跟执行类在不同的包中。
/**
* Returns a <code>Constructor</code> object that reflects the specified
* public constructor of the class represented by this <code>Class</code>
* object. The <code>parameterTypes</code> parameter is an array of
* <code>Class</code> objects that identify the constructor's formal
* parameter types, in declared order.
Constructor<X> constructor = X.class.getDeclaredConstructor(...);
// 解决访问权限的问题
constructor.setAccessible(true);
constructor.newInstance(...)