我正在尝试在服务器上输出xml并继续收到此错误。我不知道如何解决它,因为控制台中没有日志。
我曾尝试包括jersey-json依赖项,但它仍然给我同样的错误-“ http 500错误”。
我正在关注youtube上的一些教程。仍然不知道如何解决它。
这是我的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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kalykova</groupId>
<artifactId>demo</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<build>
<finalName>demo</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet
2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<properties>
<jersey.version>2.28</jersey.version>
<project.build.sourceEncoding>UTF-
8</project.build.sourceEncoding>
</properties>
</project>
这是外星人课程 包com.kalykova.demo;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Alien {
private int id;
private String name;
private int points;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
}
这是AlienResource类
package com.kalykova.demo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("aliens")
public class AlienResource
{
@GET
@Produces(MediaType.APPLICATION_XML)
public Alien getAlien()
{
System.out.println("getAlien called...");
Alien a1 = new Alien();
a1.setId(100);
a1.setName("Jennifer");
a1.setPoints(60);
return a1;
}
}
这是我收到的错误:
HTTP状态500 –内部服务器错误 类型状态报告
消息内部服务器错误
说明服务器遇到意外状况,阻止其满足请求。 我需要它来在网页上显示xml。