org.springframework.beans.factory.BeanCreationException:从外部访问时创建bean时出错

时间:2016-03-17 11:24:50

标签: java spring maven spring-mvc

我使用maven插件创建了一个带有spring 3,Maven,JAXB的Web Service客户端项目。它正在工作,并在使用main方法测试时给我结果。但我想在我的另一个项目中使用这个第三方JAR。 我的Pom就像

<properties>
    <java.version>1.6</java.version>
    <spring.version>3.1.0.RELEASE</spring.version>
    <cglib.version>2.2</cglib.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- CGLib for @Configuration -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib-nodep</artifactId>
        <version>${cglib.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.12</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws</artifactId>
        <version>1.5.2</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>springsource-milestones</id>
        <name>SpringSource Milestones Proxy</name>
        <url>https://oss.sonatype.org/content/repositories/springsource-milestones</url>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>com.yagnaiq.client.wsdl</generatePackage>
                <generateDirectory>src/main/java</generateDirectory>
                <!-- <forceRegenerate>true</forceRegenerate> -->
                <schemas>
                    <schema>
                        <url>http://localhst/WS/endpoints/copyProjectService.wsdl</url>
                    </schema>
                </schemas>
            </configuration>
        </plugin>
        <!-- <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.2</version>
        </plugin> -->
        <!-- <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-4</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.client.test.RunCopyProjectClient</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin> -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <finalName>WSClientAll</finalName>
            </configuration>
        </plugin>
    </plugins>
</build>

我的Config类看起来像

@Bean
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("com.client.wsdl");
    return marshaller;
}

@Bean
public CopyProjectClient copyProjectClient(Jaxb2Marshaller marshaller) {
    CopyProjectClient copyProjectClient = new CopyProjectClient();
    copyProjectClient.setDefaultUri("http://localhost/WS/endpoints/copyProjectService.wsdl");
    copyProjectClient.setMarshaller(marshaller);
    copyProjectClient.setUnmarshaller(marshaller);
    return copyProjectClient;
}

当我生成具有所有依赖项的jar文件并将其作为依赖项添加到另一个项目时,编译时没有错误,运行时出现跟随错误

“org.springframework.beans.factory.BeanCreationException:创建名为'clientConfiguration'的bean时出错:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[javax.enterprise.deploy .spi.status.ClientConfiguration]:指定的类是一个接口“

调用代码就像:

public MasterClient serviceCall() {
    MasterClient masterClient = null;
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ClientConfiguration.class);
    ctx.refresh();// error here
    if (webservice.equals("COPY_PROJECT")) {
        CopyProjectClient copyProjectClient = ctx
                .getBean(CopyProjectClient.class);
        copyProjectClient.setDefaultUri(wsdllocation);
        masterClient = (MasterClient) copyProjectClient;
    }
}

0 个答案:

没有答案