Java Apache CXF-JAXRSServerFactoryBean服务器已启动,但无法访问端点
我创建了两个类,一个是RestService类,另一个是main类Java Apache CXF-JAXRSServerFactoryBean服务器已启动,但无法访问端点,java,cxf,Java,Cxf,我创建了两个类,一个是RestService类,另一个是main类 import org.apache.cxf.endpoint.Server; import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; import org.apache.cxf.transport.http.HttpDestinationFactory;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.transport.http.HttpDestinationFactory;
import org.apache.cxf.transport.servlet.ServletDestinationFactory;
public class RestDemo {
public static void main(String[] args) {
final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setAddress("http://0.0.0.0:8080/");
sf.setServiceClass(RestService.class);
sf.setResourceProvider(RestService.class, new SingletonResourceProvider(new RestService()));
ServletDestinationFactory destinationFactory = new ServletDestinationFactory();
sf.getBus().setExtension(destinationFactory, HttpDestinationFactory.class);
Server server = sf.create();
server.start();
System.out.println(server.isStarted());
System.out.println(server.getDestination().getAddress().getAddress().getValue());
System.out.println(server.getEndpoint().getEndpointInfo());
try {
Thread.sleep(1000000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
sop输出表示服务器已启动,但我无法在端点上执行任何curd操作。这是在linux中实现的。我还尝试使用linux命令“netstat-anp | grep8080”检查端口8080是否正在侦听,但该命令的输出为空。任何帮助都是非常值得的
我需要它作为一个独立的程序,而不是把它当作一场与spring的战争,并在Web服务器中部署它。我使用的是最新版本的cxf,其中包含jetty,因此启动功能预计将使用嵌入式jetty启动服务器,但事实并非如此。您的类路径中似乎没有所有必需的JAR。以下是一个完整的工作项目,其中部署了一个资源: 运行以下命令以直接运行main
mvn package exec:java -Dexec.mainClass=com.example.CXFStandalone
主要内容:
pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>cxf-standalone</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cxf-standalone</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
</project>
4.0.0
com.example
cxf单机版
1.0-快照
罐子
cxf单机版
http://maven.apache.org
UTF-8
org.apache.cxf
cxf核心
3.2.1
org.apache.cxf
cxf rt前端jaxrs
3.2.1
org.apache.cxf
cxf rt传输http
3.2.1
org.apache.cxf
cxf rt传输http jetty
3.2.1
嗯,我在Apache CXF中使用了Endpoint.publish,它工作正常。也许从这里开始,然后处理JAXRSServerFactoryBean
类。Apache CXF站点的基本示例可以在@user1316830找到,如果您已经解决了问题,请关闭问题。
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>cxf-standalone</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cxf-standalone</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
</project>