2017-10-12 127 views
0

我正在實現Java Restful Web服務在maven項目中。 我能夠成功地生成XML性反應,但如果我添加JSON支持依賴我Apache Tomcat不啓動它給我的時候我跑項目
錯誤消息的錯誤:

enter image description hereJSON支持依賴不起作用

的pom.xml文件

 <dependency> 
      <groupId>org.glassfish.jersey.media</groupId> 
      <artifactId>jersey-media-moxy</artifactId> 
     </dependency> 

我的控制器類:

package com.test.restfull; 

import java.util.ArrayList; 
import java.util.Date; 
import java.util.List; 
import javax.ws.rs.Consumes; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType; 
import com.test.trex.model.TrexReport; 
import com.test.trex.service.TrexService; 



@Path("/getSO") 
public class GetDetails { 

    TrexService obj= new TrexService(); 

    @GET 
    @Consumes({MediaType.APPLICATION_JSON}) 
    @Produces({MediaType.APPLICATION_JSON}) 
    public List<TrexReport> getSoStatus() { 

     List<TrexReport> messages = new ArrayList<>(); 

     TrexReport m = new TrexReport(); 
     m.setCreated(new Date()); 
     m.setAuthor("User1"); 
     m.setId(1); 
     m.setMessage("My First Message"); 
     messages.add(m); 
     return messages; 
} 

異常消息:

Oct 12, 2017 4:22:38 PM org.apache.catalina.startup.Catalina start 
SEVERE: The required Server component failed to start so Tomcat is unable to start. 
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) 
    at org.apache.catalina.startup.Catalina.start(Catalina.java:656) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355) 
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495) 
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) 
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    ... 7 more 
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) 
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    ... 9 more 
Caused by: org.apache.catalina.LifecycleException: A child container failed during start 
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947) 
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    ... 11 more 

回答

0

檢查{} TOMCAT_HOME爲/logs/catalina.out在這種情況下更可能出現的錯誤。清理項目,刪除服務器,並嘗試在tomcat 8上再次運行它。

+0

您好Khirul,我嘗試過與清潔項目,刪除服務器仍然同樣的問題。 :( – ansh

+0

嘗試在GlassFish上運行它 –

+0

可以共享catalina.out日誌嗎? –