2017-01-17 8 views
0

JAX_RSとJerseyを使用する単純なWebサービスです。しかし、エラーA child container failed during startがあります。 これはエラーログです。JAX_RSとジャージーWebサービスで子コンテナが失敗しました

A child container failed during start 
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/RestfulWebServiceServer]] 
at java.util.concurrent.FutureTask.report(FutureTask.java:122) 
at java.util.concurrent.FutureTask.get(FutureTask.java:192) 
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943) 
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871) 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/RestfulWebServiceServer]] 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162) 

pom.xml

<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core --> 
<dependencies> 
<dependency> 
<groupId>com.sun.jersey</groupId> 
<artifactId>jersey-core</artifactId> 
<version>1.19</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/asm/asm --> 
<dependency> 
<groupId>asm</groupId> 
<artifactId>asm</artifactId> 
<version>3.1</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server --> 
    <dependency> 
<groupId>com.sun.jersey</groupId> 
<artifactId>jersey-server</artifactId> 
<version>1.19</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/junit/junit --> 
<dependency> 
<groupId>junit</groupId> 
<artifactId>junit</artifactId> 
<version>4.12</version> 
</dependency> 
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-servlet --> 
<dependency> 
<groupId>com.sun.jersey</groupId> 
<artifactId>jersey-servlet</artifactId> 
<version>1.19</version> 
</dependency> 
<dependency> 
<groupId>com.sun.jersey</groupId> 
<artifactId>jersey-json</artifactId> 
<version>1.19</version> 
</dependency> 
</dependencies> 

<build> 
<sourceDirectory>src</sourceDirectory> 
<plugins> 
    <plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.6</version> 
    <configuration> 
     <warSourceDirectory>WebContent</warSourceDirectory> 
     <failOnMissingWebXml>false</failOnMissingWebXml> 
    </configuration> 
    </plugin> 
    <plugin> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.5.1</version> 
    <configuration> 
     <source>1.8</source> 
     <target>1.8</target> 
    </configuration> 
    </plugin> 
    </plugins> 
    </build> 
    </project> 

User.java

package entities; 



    public class User{ 

private String name; 
private String id; 
private String address; 
private String email; 


public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public String getId() { 
    return id; 
} 
public void setId(String id) { 
    this.id = id; 
} 

public String getAddress() { 
    return address; 
} 
public void setAddress(String address) { 
    this.address = address; 
} 

public String getEmail() { 
    return email; 
} 
public void setEmail(String email) { 
    this.email = email; 
} 
public User(String name, String id, String address, String email) { 
    super(); 
    this.name = name; 
    this.id = id; 
    this.address = address; 
    this.email = email; 
} 
public User() { 
    super(); 
    // TODO Auto-generated constructor stub 
} 


} 

UserJSONService.java

package ws; 

import javax.ws.rs.Consumes; 
import javax.ws.rs.GET; 
import javax.ws.rs.POST; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType; 
import javax.ws.rs.core.Response; 

import entities.User; 

@Path("/json/user") 
public class UserJSONService { 

@GET 
@Path("/get") 
@Produces(MediaType.APPLICATION_JSON) 
public User getUser(){ 
    User u1 = new User(); 
    u1.setName("John Doe"); 
    u1.setId("1"); 
    u1.setAddress("Kolkata"); 
    u1.setEmail("[email protected]"); 


    return u1; 
} 

@POST 
@Path("/post") 
@Consumes(MediaType.APPLICATION_JSON) 
public Response sendUserInJSON(User user) { 

    String result = "User saved : " + user; 
    return Response.status(201).entity(result).build(); 

} 

public static double JAVA_VERSION = getVersion(); 

static double getVersion() { 
    String version = System.getProperty("java.version"); 
    int pos = version.indexOf('.'); 
    pos = version.indexOf('.', pos+1); 
    return Double.parseDouble (version.substring (0, pos)); 
} 

} 

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 
<display-name>RestfulWebServiceServer</display-name> 
<welcome-file-list> 
<welcome-file>index.html</welcome-file> 
<welcome-file>index.htm</welcome-file> 
<welcome-file>index.jsp</welcome-file> 
<welcome-file>default.html</welcome-file> 
<welcome-file>default.htm</welcome-file> 
<welcome-file>default.jsp</welcome-file> 
</welcome-file-list> 
    <servlet> 
    <servlet-name>jersey-serlvet</servlet-name> 
    <servlet- class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
<init-param> 
    <param-name>com.sun.jersey.config.property.packages</param-name> 
    <param-value>ws</param-value> 
</init-param> 
<init-param> 
    <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> 
    <param-value>true</param-value> 
</init-param> 
<load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
<servlet-name>jersey-serlvet</servlet-name> 
<url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 
</web-app> 

答えて

0

正しい依存関係を使用して

<!-- https://mvnrepository.com/artifact/asm/asm --> 
<dependency> 
<groupId>asm</groupId> 
<artifactId>asm</artifactId> 
<version>3.3.1</version> 
</dependency> 

の代わりに、ASM 3.1私の問題を解決しました。

関連する問題