- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试实例化 ObjectFactory 时,我在 Eclipse 中收到以下编译错误:
cannot instantiate the type objectfactory
此编译错误在以下行抛出:
objectFactory = new ObjectFactory();//throws error: "Cannot instantiate the type ObjectFactory"
调用类的完整代码如下:
package maintest;
import java.io.File;
import javax.naming.spi.ObjectFactory;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class Main {
private static JAXBContext context;
private static ObjectFactory objectFactory;
public static void main(String[] args) {
try {setUp();} catch (Exception e) {e.printStackTrace();}
unmarshal();
}
protected static void setUp() throws Exception {
context = JAXBContext.newInstance("generated");
objectFactory = new ObjectFactory();//throws error: "Cannot instantiate the type ObjectFactory"
}
public static <PurchaseOrderType> void unmarshal(){
Unmarshaller unmarshaller;
try {
unmarshaller = context.createUnmarshaller();
final Object object = unmarshaller.unmarshal(new File("src/test/samples/po.xml"));
} catch (JAXBException e) {e.printStackTrace();}
}
}
如何解决此错误?
最佳答案
我的猜测是您导入了错误的 ObjectFactory。您可能想要由 xjc(JAXB 相关)生成的一个,而不是 javax.naming.spi(JNDI 的服务提供者接口(interface))生成的一个。
编辑
javax.xml.bind.JAXBException: "generated" doesnt contain ObjectFactory.class or jaxb.index
确保“生成的”包包含 ObjectFactory(带有 @XmlRegistry 注释的那个,而不是 javax.naming.spi.ObjectFactory 实现)或 jaxb.index 文件。
您可能可以从代码中删除 javax.naming.spi.ObjectFactory,除非您自己实现 JNDI 实现。
关于java - 无法实例化类型 objectfactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26306894/
我需要从 java 客户端将数据协定传递到我的 wcf web 服务。数据契约(Contract)有 2 个归档,都是字符串。创建代理后,我正在尝试的代码如下 FileTransfer fs = ne
尝试实例化 ObjectFactory 时,我在 Eclipse 中收到以下编译错误: cannot instantiate the type objectfactory 此编译错误在以下行抛出: o
我正在尝试在来自第 3 方的 WSDL 中执行 wsimport(通过 netbeans 6.9.1),但它一直在 JAXB 中生成此错误: Two declarations cause a coll
我定义了以下 ObjectFactory: @XmlRegistry public class ObjectFactory { public Dogs createDogs() {
我有一个使用默认值的 WSDL 文件,我想生成 ObjectFactory 类,这些类使用 CXF 创建具有这些默认值的方法。例如,我有一个这样定义的对象
我正在使用 docx4j 创建一个 Word 文档,并且需要设置“标题”的样式,但是,我找不到执行此操作的正确函数。 private static P createIt() { org.doc
我尝试在结构图中注册命名实例。但是我的试验没有成功。 正确的做法是什么? 目前我是这样做的: IService bus = CreateInstanceOfServiceBus(); ObjectFa
使用 AngularFire,我正在扩展对象工厂,以便封装数据并允许特定功能,如 official tutorial 中所述。 .我有一个如下的数据结构: { 'articles': {
我正在创建一个 JAXBElement具有 ObjectFactory 的元素. 该对象是使用 null 创建的值,因为该字段的架构表明它有一个 nillable属性。 在编码到 xml 期间,输出文
我有两个 xsd 导入到主 xsd 中。两者具有相同的元素,但命名空间不同。因此,我为第二个 xsd(B.xsd) 创建了自定义绑定(bind)。我仍然收到“两个声明导致 ObjectFactory
我正在使用 JAXB 为导入其他模式的模式生成类。我正在使用 maven 并将 maven-jaxb2 插件配置为使用依赖项作为情节,跳过为导入的模式生成类。 然而,JAXB 不断为导入的模式生成 O
我使用 StructureMap 实现了接口(interface)注入(inject),如下所述。 ObjectFactory.Initialize(x => { x.For().Use(); });
要在 GlassFish Server 开源版 3.1.1(内部版本 12)中部署: Caused by: java.security.PrivilegedActionException: com.s
我有一个大型应用程序,它使用使用 ObjectFactory.GetInstance() 获取实例的旧方法。 现在我想将应用程序转移到使用构造函数注入(inject)注入(inject)依赖项的更正确
这是重现问题的简单测试,这是整个项目中的单个类,没有其他引用: [TestFixture] public class ObjectFactoryTests { [Test] publi
在使用最新的 StructureMap 版本 (3.1.6.191) 升级我们的解决方案后,我收到了很多过时的警告。这些警告来自 StructureMap,其中 ObjectFactory 类将在未来
我正在尝试制作网络服务,但我遇到了两种情况。 xsd 文件有两种类型,第一种是:
我正在开发一个工厂,它可以使用 Class 参数实例化 Skill 类型的对象。该工厂的代码是: public static final class AbilityFactory { priv
我有一个 XSD 选择,它们都是 javax.xml.datatype.XMLGregorianCalendar 类型。按照建议,我使用了 ObjectFactory 和 JAXBElement 来区
我们已经在我们的系统中使用 JAXB 2.1 很长时间了。我们有一个使用 Ant 构建的平台,并生成一堆部署在 OSGi 运行时中的包。我们使用 Java SE 6。 我们在构建过程中使用 JAXB
我是一名优秀的程序员,十分优秀!