2016-10-15 11 views
1

私は安らかなAPIのコードを書いていますが、メソッドが呼び出されていません。 "コンテキストルートが見つかりません"というエラーが発生しました。私はここで自由プロファイルSpring mvc4のRestControllerを呼び出すメソッドがありません

を使用しています

は私のコード コントローラ

@RestController 
public class demoAPIController { 

    @RequestMapping(value = "/restcall", method = RequestMethod.GET, produces = "application/json") 
    public ResponseEntity<String> GetParseResume() { 
     return new ResponseEntity("hello", HttpStatus.OK); 
    } 
} 

あるWebAppInitializer

public class WebAppInitializer implements WebApplicationInitializer { 

    @Override 
    public void onStartup(ServletContext servletContext) throws ServletException { 
     WebApplicationContext context = getContext(); 
     servletContext.addListener(new ContextLoaderListener(context)); 
     ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); 
     dispatcher.setLoadOnStartup(1); 
     dispatcher.addMapping("*.html"); 
     dispatcher.addMapping("*.pdf"); 
     dispatcher.addMapping("*.json"); 
    } 

    private AnnotationConfigWebApplicationContext getContext() 
    { 
     AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();  
     context.register(WebConfig.class); 
     return context; 
    } 

} 

ここWebConfig.java

@Configuration 
    @EnableWebMvc 
    @ComponentScan(basePackages = "com.demo") 
    public class WebConfig extends WebMvcConfigurerAdapter { 
     @Bean 
     public InternalResourceViewResolver getInternalResourceViewResolver() { 
      InternalResourceViewResolver viewResolve = new InternalResourceViewResolver(); 
      viewResolve.setPrefix("/WEB-INF/jsp/"); 
      viewResolve.setSuffix(".jsp"); 
      return viewResolve; 
     } 
    } 

リバティーサーバーを起動するときにSpringツールスイートにエラーが表示される

[ERROR ] CWWKZ0002E: An exception occurred while starting the application demo1. The exception message was: java.lang.IllegalStateException: com.ibm.wsspi.adaptable.module.UnableToAdaptException: java.util.zip.ZipException: invalid LOC header (bad signature) 
+1

jarが壊れているようです。関連するjarファイルをmavenキャッシュから削除してリロードすることを検討します。 –

+0

@ mh-dev私はプロジェクトを右クリックし、Maven - > Update Projectに行きました。まだ動作していません..どのようにMavenのキャッシュを削除するには? –

答えて

0

いくつかのバックエンド側のファイルが壊れたようです。

pom.xml - > maven - > cleanを右クリックしてもう一度インストールしました。

エラーが解決しました。

0

リバティーがサーブレット3.0以降をサポートしていない可能性があります。だから、

春ブーツのServletContext を初期化するために、サーブレット3.0のAPIを使用しています(サーブレットなどを登録する)ので、あなたがサーブレットに の外箱を同じアプリケーションを使用することはできませんことをお勧めします春に応じていくつかの調整を行う必要があります2.5コンテナ。しかし、いくつかの特別なツールを使用して古いコンテナでSpring Bootアプリケーションを実行することは可能です。依存関係としてorg.springframework.boot:spring-boot-legacyをインクルードしている場合(Springブートのコアとは別に管理され、現在は1.0.2.RELEASEで利用可能です)、web.xmlを作成するだけです。アプリケーション・コンテキストとフィルタとサーブレットを作成するためのコンテキスト・リスナーを宣言します。

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-servlet-2-5

<?xml version="1.0" encoding="UTF-8"?> 
 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
 

 
    <context-param> 
 
     <param-name>contextConfigLocation</param-name> 
 
     <param-value>demo.Application</param-value> 
 
    </context-param> 
 

 
    <listener> 
 
     <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class> 
 
    </listener> 
 

 
    <filter> 
 
     <filter-name>metricFilter</filter-name> 
 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
 
    </filter> 
 

 
    <filter-mapping> 
 
     <filter-name>metricFilter</filter-name> 
 
     <url-pattern>/*</url-pattern> 
 
    </filter-mapping> 
 

 
    <servlet> 
 
     <servlet-name>appServlet</servlet-name> 
 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
 
     <init-param> 
 
      <param-name>contextAttribute</param-name> 
 
      <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value> 
 
     </init-param> 
 
     <load-on-startup>1</load-on-startup> 
 
    </servlet> 
 

 
    <servlet-mapping> 
 
     <servlet-name>appServlet</servlet-name> 
 
     <url-pattern>/</url-pattern> 
 
    </servlet-mapping> 
 

 
</web-app>

+0

その時初めて試してみたときに動いていたので、バージョンに問題はないと確信していました。突然、この種のエラーが表示されていました。何かが壊れているか、裏側に何らかの変更が加えられている可能性があります。 –

+0

あなたはきれいにして、新しいビルドを試みることができます – kuhajeyan

+0

きれいにする方法?私はmavenを更新しました。 –

関連する問題