Web service on Wildfly27 with jakarta.jakartaee-api10 . Successful deployment but can't get junit test to run successfully

huangapple go评论66阅读模式
英文:

Web service on Wildfly27 with jakarta.jakartaee-api10 . Successful deployment but can't get junit test to run successfully

问题

The issue you're encountering, "Eine WebService-Annotation ist in Klasse nicht vorhanden: cs.edu.appserver.jaxws.AccountWSItf," indicates that the web service annotation is missing in your interface AccountWSItf. However, based on the code you provided, you do have the @WebService annotation in the AccountWSItf interface:

import jakarta.jws.WebMethod;
import jakarta.jws.WebService;

@WebService
public interface AccountWSItf {
    @WebMethod
    public void newAccount(String name);

    @WebMethod
    public void withdraw(String name, long amount) throws RuntimeException;

    @WebMethod
    public void deposit(String name, long amount);

    @WebMethod
    public Account findAccountByName(String name);
}

Since you have already annotated the interface, there might be another issue causing the problem. Make sure you have the necessary dependencies correctly configured in your project, and ensure that the packages are being imported correctly in your JUnit test class. Double-check that the JUnit test class is in the correct package and that there are no typos or other issues in the test class.

If the problem persists, you might want to review your project configuration and dependencies carefully, as well as any custom settings related to your web service and testing environment. It's possible that there could be a specific configuration issue causing this problem.

英文:

I successfully deployed a Web Service on Wildfly 27 with jakarta.jakartaee-api 10.0.0.
But I just can't get a junit test to access the web service.
I can call the wsdl via the browser and already tried all kinds of package imports to get the client to run, but I'm always getting package errors.
Have already read numerous posts and tried out the suggested package imports but all fails.

This is the wildfly console after deployment

 address=http://localhost:8080/ejb-server-basic-jaxws/AccountWS
 implementor=cs.edu.appserver.jaxws.AccountWS
 serviceName={http://jaxws.appserver.edu.cs/}AccountWSService
 portName={http://jaxws.appserver.edu.cs/}AccountWSPort
 annotationWsdlLocation=null
 wsdlLocationOverride=null
 mtomEnabled=false
 publishedEndpointUrl=http://localhost:8080/ejb-server-basic-jaxws/AccountWS

this is the wsdl

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://jaxws.appserver.edu.cs/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="AccountWSService" targetNamespace="http://jaxws.appserver.edu.cs/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://jaxws.appserver.edu.cs/" elementFormDefault="unqualified" targetNamespace="http://jaxws.appserver.edu.cs/" version="1.0">
<xs:element name="account" type="tns:account"/>
<xs:element name="deposit" type="tns:deposit"/>
<xs:element name="depositResponse" type="tns:depositResponse"/>
<xs:element name="findAccountByName" type="tns:findAccountByName"/>
<xs:element name="findAccountByNameResponse" type="tns:findAccountByNameResponse"/>
<xs:element name="newAccount" type="tns:newAccount"/>
<xs:element name="newAccountResponse" type="tns:newAccountResponse"/>
<xs:element name="withdraw" type="tns:withdraw"/>
<xs:element name="withdrawResponse" type="tns:withdrawResponse"/>
<xs:complexType name="withdraw">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element name="arg1" type="xs:long"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="withdrawResponse">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="deposit">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element name="arg1" type="xs:long"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="depositResponse">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="findAccountByName">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="findAccountByNameResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:account"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="account">
<xs:sequence>
<xs:element name="amount" type="xs:long"/>
<xs:element minOccurs="0" name="id" type="xs:long"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="newAccount">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="newAccountResponse">
<xs:sequence/>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="findAccountByNameResponse">
<wsdl:part element="tns:findAccountByNameResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="depositResponse">
<wsdl:part element="tns:depositResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="findAccountByName">
<wsdl:part element="tns:findAccountByName" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="withdrawResponse">
<wsdl:part element="tns:withdrawResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="withdraw">
<wsdl:part element="tns:withdraw" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="deposit">
<wsdl:part element="tns:deposit" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="newAccountResponse">
<wsdl:part element="tns:newAccountResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="newAccount">
<wsdl:part element="tns:newAccount" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="AccountWSItf">
<wsdl:operation name="withdraw">
<wsdl:input message="tns:withdraw" name="withdraw"> </wsdl:input>
<wsdl:output message="tns:withdrawResponse" name="withdrawResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:operation name="deposit">
<wsdl:input message="tns:deposit" name="deposit"> </wsdl:input>
<wsdl:output message="tns:depositResponse" name="depositResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:operation name="findAccountByName">
<wsdl:input message="tns:findAccountByName" name="findAccountByName"> </wsdl:input>
<wsdl:output message="tns:findAccountByNameResponse" name="findAccountByNameResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:operation name="newAccount">
<wsdl:input message="tns:newAccount" name="newAccount"> </wsdl:input>
<wsdl:output message="tns:newAccountResponse" name="newAccountResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AccountWSServiceSoapBinding" type="tns:AccountWSItf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="withdraw">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="withdraw">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="withdrawResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="deposit">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="deposit">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="depositResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="findAccountByName">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="findAccountByName">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="findAccountByNameResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="newAccount">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="newAccount">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="newAccountResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AccountWSService">
<wsdl:port binding="tns:AccountWSServiceSoapBinding" name="AccountWSPort">
<soap:address location="http://localhost:8080/ejb-server-basic-jaxws/AccountWS"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

this is my current 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cs.edu.appserver</groupId>
<artifactId>ejb-server-basic-jaxws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.server.bom>21.0.1.Final</version.server.bom>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jakartaee.version>10.0.0</jakartaee.version>
<version.wildfly.maven.plugin>2.0.0.Final</version.wildfly.maven.plugin>
<apache.log4j2.version>2.20.0</apache.log4j2.version>
<junit.version>5.3.1</junit.version>
<skipTests>true</skipTests>
<version.wildfly>26.1.1.Final</version.wildfly>
</properties>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<type>pom</type>
<scope>compile</scope>
<version>${version.wildfly}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.2</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>${jakartaee.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${apache.log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${apache.log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<filename>${project.build.finalName}.war</filename>
<add-user>
<users>
<user>
<username>xxxx</username>
<password>yyyy</password>
</user>
</users>
</add-user>
</configuration>
</plugin>
</plugins>
</build>
</project>

this is my junit test

	public void testWebService() {
String name = "John Smith";
try {
URL url = new URL("http://localhost:8080/ejb-server-basic-jaxws/AccountWS?wsdl");
QName qname = new QName("http://jaxws.appserver.edu.cs/", "AccountWSService");
Service service = Service.create(url, qname);
AccountWSItf ws = service.getPort(AccountWSItf.class);
ws.newAccount(name);
System.out.println("Created account name " + name);
ws.deposit(name, 1000);
System.out.println("Deposit $ 1000 ");
ws.withdraw(name, 500);
System.out.println("Withdraw $ 500 ");
Account account = ws.findAccountByName(name);
assertNotNull(account);
long money = account.getAmount();
assertEquals(500l, money);
System.out.println("Account balance is " + account.getAmount());
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception: " + e);
}
}

and this is the console when I run the test

com.sun.xml.ws.model.RuntimeModelerException: Eine WebService-Annotation ist in Klasse nicht vorhanden: cs.edu.appserver.jaxws.AccountWSItf
at com.sun.xml.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1581)
at com.sun.xml.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1572)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:428)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:449)
at javax.xml.ws.Service.getPort(Service.java:210)
at cs.edu.appserver.jaxws.test.ServiceTest.testWebService(ServiceTest.java:60)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
Exception: com.sun.xml.ws.model.RuntimeModelerException: Eine WebService-Annotation ist in Klasse nicht vorhanden: cs.edu.appserver.jaxws.AccountWSItf
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:95)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:91)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:60)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

the line

Eine WebService-Annotation ist in Klasse nicht vorhanden: cs.edu.appserver.jaxws.AccountWSItf

says that there is no web service annotation in class AccountWSItf

this is the interface AccountWSItf

import jakarta.jws.WebMethod;
import jakarta.jws.WebService;
@WebService
public interface AccountWSItf {
@WebMethod
public void newAccount( String name);
@WebMethod
public void withdraw(String name, long amount) throws RuntimeException;
@WebMethod
public void deposit(String name, long amount);
@WebMethod
public Account findAccountByName(String name);
}

this is its implementation

import jakarta.inject.Inject;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style= SOAPBinding.Style.RPC)
public class AccountWS implements AccountWSItf{
@Inject
AccountManager ejb;
public void newAccount(@WebParam(name = "name") String name) {
ejb.createAccount(name);
}
public void withdraw(@WebParam(name = "name") String name,
@WebParam(name = "amount") long amount) throws RuntimeException {
ejb.withdraw(name, amount);
}
public void deposit(@WebParam(name = "name") String name,
@WebParam(name = "amount") long amount) {
ejb.deposit(name, amount);
}
@WebResult(name = "BankAccount")
public Account findAccountByName(String name) {
return ejb.findAccount(name);
}
}

followed numerous tutorials and posts on stackoverflow but just can't get the junit test to run.

答案1

得分: 1

你混合使用了 Jakarta EE 10 和 Java EE 8,所以无法正常工作:AccountWSItf 是 Jakarta EE 10 注释的,而你的客户端代码正在寻找 'old' javax 注释。你的代码需要保持一致。

英文:

You are mixing JakartaEE 10 and JavaEE 8 so it won't work: AccountWSItf is JakartaEE 10 annotated while your client code is loking for 'old' javax annotation. You need to be coherent in your code

答案2

得分: 0

I finally found the dependency versions that work together.

pom.xml文件中的属性:

<properties>
    <skipTests>true</skipTests>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.wildfly.maven.plugin>2.0.0.Final</version.wildfly.maven.plugin>
    <maven.compiler.source.version>11</maven.compiler.source.version>
    <maven.compiler.target.version>11</maven.compiler.target.version>
    <jakartaee.version>10.0.0</jakartaee.version>
    <jaxws-maven-plugin.version>3.0.2</jaxws-maven-plugin.version>
    <junit.version>5.3.1</junit.version>
    <apache.log4j2.version>2.20.0</apache.log4j2.version>
</properties>

用于创建客户端存根的jax-ws插件:

<!-- 使用jax-ws maven插件进行构建:jaxws:wsimport -->
<plugin>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>${jaxws-maven-plugin.version}</version>
    <configuration>
        <wsdlUrls>
            <wsdlUrl>http://localhost:8080/jakarta-soap-with-client-1.0.0/CountryServiceImpl?wsdl</wsdlUrl>
        </wsdlUrls>
        <keep>true</keep>
        <packageName>cs.edu.jakarta.soap.client</packageName>
        <destDir>src/main/java/cs/edu/jakarta/soap/client</destDir>
        <sourceDestDir>src/main/java</sourceDestDir>
    </configuration>
</plugin>

用于运行单元测试的依赖项:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>3.0.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-ri</artifactId>
    <version>2.3.1</version>
    <type>pom</type>
    <scope>test</scope>
</dependency>

然后进行Maven构建:

clean install jaxws:wsimport

在我的JUnit测试中,我可以初始化服务:

@BeforeAll
public static void setup() {
    try {
        service = new CountryServiceImplService();
        countryService = service.getCountryServiceImplPort();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

希望这些翻译有帮助。

英文:

I finally found the dependency versions that work together.

properties of the pom.xml

&lt;properties&gt;
&lt;skipTests&gt;true&lt;/skipTests&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;version.wildfly.maven.plugin&gt;2.0.0.Final&lt;/version.wildfly.maven.plugin&gt;
&lt;maven.compiler.source.version&gt;11&lt;/maven.compiler.source.version&gt;
&lt;maven.compiler.target.version&gt;11&lt;/maven.compiler.target.version&gt;
&lt;jakartaee.version&gt;10.0.0&lt;/jakartaee.version&gt;
&lt;jaxws-maven-plugin.version&gt;3.0.2&lt;/jaxws-maven-plugin.version&gt;
&lt;junit.version&gt;5.3.1&lt;/junit.version&gt;
&lt;apache.log4j2.version&gt;2.20.0&lt;/apache.log4j2.version&gt;
&lt;/properties&gt;

jax-ws plugin to create the client stubs

		&lt;!-- jax-ws maven plugin use with maven build:  jaxws:wsimport  --&gt;
&lt;plugin&gt;
&lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
&lt;artifactId&gt;jaxws-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${jaxws-maven-plugin.version}&lt;/version&gt;
&lt;configuration&gt;
&lt;wsdlUrls&gt;
&lt;wsdlUrl&gt;
http://localhost:8080/jakarta-soap-with-client-1.0.0/CountryServiceImpl?wsdl</wsdlUrl>
&lt;/wsdlUrls&gt;
&lt;keep&gt;true&lt;/keep&gt;
&lt;packageName&gt;cs.edu.jakarta.soap.client&lt;/packageName&gt;
&lt;destDir&gt;src/main/java/cs/edu/jakarta/soap/client&lt;/destDir&gt;
&lt;sourceDestDir&gt;src/main/java&lt;/sourceDestDir&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;

and the dependencies to run the unit tests

    &lt;dependency&gt;
&lt;groupId&gt;
com.sun.xml.ws&lt;/groupId&gt;
&lt;artifactId&gt;jaxws-rt&lt;/artifactId&gt;
&lt;version&gt;3.0.0&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;
com.sun.xml.ws&lt;/groupId&gt;
&lt;artifactId&gt;jaxws-ri&lt;/artifactId&gt;
&lt;version&gt;2.3.1&lt;/version&gt;
&lt;type&gt;pom&lt;/type&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;

the maven build is then

clean install jaxws:wsimport

In my junit test I can then init the service

@BeforeAll
public static void setup() {
try {
service = new CountryServiceImplService();
countryService = service.getCountryServiceImplPort();
} catch (Exception e) {
e.printStackTrace();
}
}

huangapple
  • 本文由 发表于 2023年5月21日 16:02:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76298863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定