当前位置: 首页 > 知识库问答 >
问题:

cxf-Spring Boot集成测试时出错页面"未找到"

马权
2023-03-14

我第一次尝试用ApacheCXF和SpringBoot开发一个soap jax ws web服务;我对这些技术的使用非常陌生。为此,我创建了一个web应用程序类型的maven项目,旨在实现我的web层服务(知道dao层和专业将通过一个实际上是带有spring boot的project maven java应用程序的程序调用)。所有这些都耦合在一个企业应用程序中。

然后我在web项目中构建了apachecxf和springboot,就像我的pom一样。xml:

com.xxx.dev模块-web 0.0.1-SNAPSHOT战${project.build.directory}/认可UTF-8

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-websocket</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.1.7</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-bindings-soap</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-bindings-xml</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.1.7</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>mobilepayment-dao</artifactId>
        <version>${project.version}</version>
    </dependency>
         <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-bindings-xml</artifactId>
        <version>3.1.7</version>
        <scope>provided</scope>
    </dependency>
       <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-bindings-soap</artifactId>
        <version>3.1.7</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-core</artifactId>
        <version>3.1.7</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>


<repositories>
    <repository>
        <id>mavencentral</id>
        <name>Maven Central</name>
        <url>https://repo1.maven.org/maven2/</url>
        <layout>default</layout>
    </repository>
</repositories>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我的Spring Boot配置类:

@Configuration@ImportResource({“classpath:cxfservlet.xml})公共类MyConfig{

@Autowired(required=true)
private Bus bus;

@Bean
public ServletRegistrationBean cxfServlet() {
    ServletRegistrationBean servlet = new ServletRegistrationBean(new CXFServlet(), "/services/*");
    servlet.setLoadOnStartup(1);
    return servlet;
}

@Bean
public IServicesWeb momoService() {
    return new MomoServices();
}

@Bean
public Endpoint endpoint() {
    EndpointImpl endpoint = new EndpointImpl(bus, momoService());
    endpoint.publish("/momo");
    return endpoint;
} }

Web服务接口

@WebService公共接口IServicesWeb扩展IMetierGestionCompte

实现类:

@Component@WebService公共类MomoServices实现IServicesWeb{

private IMetierGestionCompte gcMetier;

public void setGcMetier(MetierImplGestionCompte gcMetier) {
    this.gcMetier = gcMetier;
}

@WebMethod
@Override
public void ajouterCompte( ) {
    gcMetier.ajouterCompte( );
}

Web项目在Wildfly上部署得非常好,在“http://localhost:8080/Web mobilepayment/”上有一个“hello world”

我担心的是,当我尝试检查我的web服务和地址wsdl时:“http://localhost:8080/web mobilepayment/services”和“http://localhost:8080/web mobilepayment/services?wsdl”如果不是消息“not found”,那么什么都不会出现(没有集成cxf Spring Boot的痕迹),我不明白为什么我的web服务没有工作,请帮帮我!

共有1个答案

逄学潞
2023-03-14

您的Hello world将由您的Web servlet显示在web-mobile epayment下。如果您想访问网络服务,您必须在/service/下使用CXF servlet路径。

您使用momopath发布了Web服务,因此必须调用http://localhost:8080/服务/momo?wsdl

 类似资料:
  • 我正在使用一个带有spring boot 2.0.0.rc1的多项目分级器。我的子项目之一是SpringBoot应用程序,其中包含了我的集成测试。 集成测试用WebEnvironment.random_port标记为@springboottest。由于未解析的依赖关系(在另一个子项目中声明的服务,的同级),测试失败,使用了gradle命令行,但在Eclipse IDE中成功。 如果有人有主意?如何

  • 我有几个繁重的Spring集成测试(是的,这不是最好的方法,我没有时间正确地模拟所有外部dep) 下面是测试的典型注释 由于以下原因,测试会定期失败: 这里有两个问题:1、让测试共存的正确方式是什么?我在surefire插件中设置了forkCount=0。好像有帮助 2.1. 在每次测试期间,我实际上不需要启动所有的

  • 对于迁移管理,我决定使用Prisma Migrate,而不是节点pg Migrate(PostgreSQL)。我按照此链接中的说明操作,一切正常。然而,主要的挑战是,我的集成测试在尝试在测试数据库(而不是开发数据库)上运行迁移时失败。如何覆盖测试数据库的配置? 在节点pg migrate中,我可以在运行集成测试之前简单地提供配置:

  • 我试图对一个用Spring的@Async注释的方法进行单元(集成)测试。测试在内存h2数据库中设置一些数据,然后运行异步方法。异步代码看不到测试数据:O删除@Async修复了该问题。 任何帮助?:)

  • 当我试图从Spring Boot应用程序中调用JUnit测试用例时,我遇到了以下错误: 我在测试类中使用了这个注释。 @RunWith(SpringRunner.class) 在我从项目依赖项添加JUnit库后,它给出了以下错误: 我的Spring启动版本是2.0.4。编辑器是SpringToolSuite。有人能帮我解决这个问题吗? 谢谢