1

gwt -2.7spring-4.2.3で動作させようとしています。構成は次のとおりです。

web.xml

<!-- spring config -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Spring GWT integration -->
<servlet>
    <servlet-name>springGwtRemoteServiceServlet</servlet-name>
    <servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>springGwtRemoteServiceServlet</servlet-name>
    <url-pattern>/idp_web/service/*</url-pattern>
</servlet-mapping>

applicationContext.xml

<beans 
...
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
....
default-lazy-init="true">

<!-- auto-inject bean by annotation mechanism -->
<context:component-scan
    base-package="com.vsi.idp.analysis.server,
                    com.vsi.idp.base.server,
                    com.vsi.idp.kpi.server,
                    com.vsi.idp.map.server,//SeniorQueryServiceImpl is under this package
                    com.vsi.idp.statistics.server" />

     //other configurations
</beans>

GWT サービス

@RemoteServiceRelativePath("service/querySenior")
public interface SeniorQueryService extends RemoteService{...}

サービス実装

@Service("querySenior")
public class SeniorQueryServiceImpl extends RemoteServiceServlet implements SeniorQueryService{...}

スポック単体テストは正常に動作します

@ContextConfiguration(locations = "file:war/WEB-INF/applicationContext.xml")
public class SeniorQueryServiceImplTest extends Specification{

  @Autowired
  SeniorQueryServiceImpl service

  def "query by full address"(){
      //blabla
  }
}

gwt プロジェクトを実行すると、次のことがわかります。

Failed to load resource: the server responded with a status of 500 (Server Error)

エラー スタックは次のようになります。

[WARN] Exception while dispatching incoming RPC call
java.lang.IllegalArgumentException: Spring bean not found: querySenior
at org.spring4gwt.server.SpringGwtRemoteServiceServlet.getBean(SpringGwtRemoteServiceServlet.java:96)
at org.spring4gwt.server.SpringGwtRemoteServiceServlet.getBean(SpringGwtRemoteServiceServlet.java:55)
at org.spring4gwt.server.SpringGwtRemoteServiceServlet.processCall(SpringGwtRemoteServiceServlet.java:31)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)

おもう:

1,"500(server error)" tells that gwt has recognized spring service
2,spring service unit test works fine,so spring configuration is right 

この問題は spring4gwt に起因する可能性があります。この問題を解決するにはどうすればよいですか?

4

1 に答える 1

-1

これは実際に機能するソリューションである必要があります。

SpringGwtRemoteServiceServlet#getBean

protected Object getBean(String name) {
    WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    if (applicationContext == null) {
        throw new IllegalStateException("No Spring web application context found");
    }
    if (!applicationContext.containsBean(name)) {
        throw new IllegalArgumentException("Spring bean not found: " + name);
    }
    return applicationContext.getBean(name);
}

applicationContext に Bean がなかったために Exception が発生したことがわかります

この Bean を applicatinContext で暗黙的に宣言してみてください。


推薦

RPC が好きな方は、GWTP とその GWT ディスパッチ モジュールをご覧になることをお勧めします。アプローチは Spring4Gwt に似ていますが、Command パターンと通信する方がはるかに優れています。

通常の GWT RPC アプローチでは、大規模なプロジェクトのサービスは 1 か所に非常に多くのメソッドが散らばってしまい、新しいメソッドに対して新しい Async ペアを作成することに満足できなくなります。

または、JSON と通信し、GWT シリアル化アプローチを回避するのが最善の方法です。後でアプリと簡単に統合できます。

于 2015-11-23T19:40:12.787 に答える