2016-04-01 11 views
0

私がやっていることが正しいか誰にでも教えてください。同じパッケージとウェブサービスを指す2つのサーブレット

私はそれが動作しないと私は私が行方不明ですかわからない私は[到達範囲]をアクセスする別のサーブレットをクリートしたかった内部宣言私のサーブレットと、このweb.xmlファイル、同じWebサービス

を持っていますあなたは助けてくださいできますか?ここ は私のサーブレットとのコードです:

<!-- old servlet--> 

<servlet> 
    <servlet-name>api</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring-config/api-r-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>3</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>api</servlet-name> 
    <url-pattern>/sitesApi/*</url-pattern> 
</servlet-mapping> 

<!-- my secod servmet V2 --> 
<servlet> 
    <servlet-name>webservice</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring-config/api-web-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>3</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>webservice</servlet-name> 
    <url-pattern>/api/*</url-pattern> 
</servlet-mapping> 

だから私の他のXMLファイルに対して、API-ウェブサーブレットそれは全く同じです: http://localhost:8080/sitesApi/v1/mysite?id=1&fields=site.name:私が使用して私のURLのテストのための

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" 
    > 
<context:annotation-config/> 
<context:component-scan base-package="com.me.project.rest.api" /> 
<mvc:annotation-driven />  
</beans> 

それは動作しますが、他のサーブレットで試してみると、それはありません:

*******版**他の方法

@RequestMapping(value = "/v2/mySite", method = RequestMethod.GET) 
public @ResponseBody 
Object SitesV2(@RequestParam(value = "ajouterstatus", required = false) Integer ajouterstatus, 
     @RequestParam(value = "monadresse", required = false) String monadresseHttpServletRequest request, HttpServletResponse responseHttp{ 

try { 
     appname = request.getHeaders("Name").nextElement().toString(); 
    } catch (Exception e) { 
     return new Result("", ": AppName is Empty"); 
    } 

任意のアイデアと***

@RequestMapping(value = "/v1/mySite", method = RequestMethod.GET) 
public @ResponseBody 
Object SitesV1(@RequestParam(value = "ajouterstatus", required = false) Integer ajouterstatus, 
     @RequestParam(value = "monadresse", required = false) String monadresseHttpServletRequest request, HttpServletResponse responseHttp{ 

try { 
     appname = request.getHeaders("Name").nextElement().toString(); 
    } catch (Exception e) { 
     return new Result("", ": AppName is Empty"); 
    } 

だから、まったく同じこと?? ありがとう

+0

あなたがURLにアクセスするときに、サーバーを起動するときや、あなたのログにエラーがありますか? –

+0

@CédricCouraletコメントありがとうございました。私は全くエラーがありません。デバッグモードでappを実行し、最初のリンクで私のパラメータを回復することができました。パラメータがnullで、これが名前を返さない理由です。 –

+0

パラメータを取得するために使用しているコードを提供する必要があると思います。 –

答えて

0

Dispatcherサーブレットは、必要な数だけ使用できますが、それぞれ独自のxmlファイルを使用して構成する必要があります。

サーブレットが「api」の場合、「api-servlet.xml」という名前の設定ファイルが必要です。

ここで、 'webservice'ディスパッチャーサーブレットが機能するには、 'webservice-servlet.xml'が必要です。

あなたは以下の回答を参照することができ

How does DispatcherServlet work if we have multiple XML Configuration file?

Multiple application context, multiple dispatcher servlets?

+0

本当に私はweb.xmlとwebservice-servlet.xmlとapi-servlet.xmlの3つのXMLファイルを持っていますが、それでもまだ動作しません! –

+0

この 'webservice-servlet.xml'は' api-web-servlet.xml'であり、この 'api-servlet.xml'は' api-r-servlet.xml'であり、これらのXMLファイルは両方とも** beans /コンテキスト注釈とベースパッケージ** –

+0

2番目のサーブレットの中に何を置くべきか教えてください。 'webservice-servlet.xml' ?? –

関連する問題