packagename不包含ObjectFactory.class或jaxb.in​​dex

时间:2014-09-11 11:05:32

标签: spring maven jaxb jaxb2 maven-jaxb2-plugin

在将我的项目部署到tomcat-server时,我不断得到这个例外:

引起:org.springframework.beans.factory.BeanCreationException:创建名称为' marshaller'的init时出错:init方法的调用失败;嵌套异常是org.springframework.oxm.UncategorizedMappingException:未知的JAXB异常;嵌套异常是javax.xml.bind.JAXBException:" be.icredit.einvoice.proxy.customerdaoservice"不包含ObjectFactory.class或jaxb.in​​dex

但它确实有一个ObjectFactory.class!

我使用Spring,Maven和Jaxb2

我的POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>be.icredit</groupId>
    <artifactId>einvoice</artifactId>
    <packaging>war</packaging>
    <name>einvoice Portlet</name>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <liferay.maven.plugin.version>6.2.10.6</liferay.maven.plugin.version>
        <liferay.version>6.2.1</liferay.version>
        <spring.suite.version>3.2.10.RELEASE</spring.suite.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>com.liferay.maven.plugins</groupId>
                <artifactId>liferay-maven-plugin</artifactId>
                <version>${liferay.maven.plugin.version}</version>
                <executions>

                </executions>
                <configuration>
                    <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                    <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
                    <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
                    <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
                    <liferayVersion>${liferay.version}</liferayVersion>
                    <pluginType>portlet</pluginType>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.9.0</version>

                <executions>
                    <execution>
                        <id>BatchDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/batchdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>BatchDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.batchdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>CustomerAccountDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/customeraccountdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>CustomerAccountDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.customeraccountdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>CustomerDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/customerdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>CustomerDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.customerdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>DocumentDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/documentdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>DocumentDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.documentdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>DocumentTemplateDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/documenttemplatedaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>DocumentTemplateDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.documenttemplatedaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>EmailStatusDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/emailstatusdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>EmailStatusDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.emailstatusdaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>EmailTemplateDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/emailtemplatedaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>EmailTemplateDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.emailtemplatedaoservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>FileService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/fileservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>FileService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.fileservice</generatePackage>
                        </configuration>
                    </execution>
                    <execution>
                        <id>SenderDaoService-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateDirectory>target/senderdaoservice</generateDirectory>
                            <schemaDirectory>src/main/resources/wsdl</schemaDirectory>
                            <schemaIncludes>
                                <include>SenderDaoService.wsdl</include>
                            </schemaIncludes>
                            <generatePackage>be.icredit.einvoice.proxy.senderdaoservice</generatePackage>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>portal-service</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-bridges</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-taglib</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-java</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.portlet</groupId>
            <artifactId>portlet-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc-portlet</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.suite.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>

我真的很无能......

我的applicationcontext:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:annotation-config />
    <context:component-scan base-package="be.icredit.einvoice.service, be.icredit.einvoice.webserviceTest" />


    <oxm:jaxb2-marshaller id="marshaller" contextPath="be.icredit.einvoice.proxy.customerdaoservice"/>
    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
         <property name="marshaller" ref="marshaller" /> 
         <property name="unmarshaller" ref="marshaller" /> 
        <property name="defaultUri"
            value="http://localhost:8081/ws-demo/account-balance-service" />
    </bean>

</beans>

1 个答案:

答案 0 :(得分:2)

首先,让我们检查您是否遇到Maven构建或IDE中的问题。

你说你的构建似乎工作正常。

  • 你有一个简单的解组测试,检查解组真的有用吗?制作一个并确保它有效。
  • 检查生成的war - 它是否包含WEB-INF/classes中生成的所有课程?
  • 您有多次执行,是否存在所有生成的包(WEB-INF/classes)?

如果排除了maven构建的问题,请检查您的IDE。我认为你正在使用Eclipse:

  • 您是否将所有生成的目录视为Eclipse源文件夹?
  • 您的简单解组测试(见上文)是否适用于Eclipse?
  • 您是否必须以某种方式配置哪些文件夹部署到Tomcat?
  • 您是否需要将编译目标重定向到WEB-INF/classes

有很多地方可能会出错。一个简单的单元测试将有助于检查每一步,找出缺失的内容。

正如我之前所说,maven-jaxb2-plugin确实将您的目标目录添加为编译源根目录(除非您明确地将其配置为不执行此操作)。因此,Eclipse中的m2eclipse之类的Maven集成插件应该将这些目录添加为源文件夹。在某种意义上,您的项目与“正常”设置略有不同,即您拥有war项目和多次执行。但我仍然认为这必须有效,maven-jaxb2-plugin does pretty standard stuff here

    if (getAddCompileSourceRoot()) {
        getProject().addCompileSourceRoot(getGenerateDirectory().getPath());
    }

这与build-helper-maven-plugin does

完全相同
this.project.addCompileSourceRoot( source.getAbsolutePath() );