2016-10-04 6 views
1

私はSpringのプロジェクトからweb.xmlとapplicationContext.xmlを持っています。 私はこれを変更して、自分のプロジェクトのJava設定だけを取得したいが、どうすればいいのか分からない。Spring - xmlからJavaの設定

ウェブ-XML

<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

    <display-name>Spring + JAX-WS</display-name> 

    <servlet> 
    <servlet-name>jaxws-servlet</servlet-name> 
     <servlet-class> 
     com.sun.xml.ws.transport.http.servlet.WSSpringServlet 
     </servlet-class> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>jaxws-servlet</servlet-name> 
    <url-pattern>/hello</url-pattern> 
    </servlet-mapping> 

    <!-- Register Spring Listener --> 
    <listener> 
    <listener-class> 
     org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
    </listener> 

</web-app> 

applicationContext.xmlを任意の提案のための

<?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:ws="http://jax-ws.dev.java.net/spring/core" 
     xmlns:wss="http://jax-ws.dev.java.net/spring/servlet" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
     http://jax-ws.dev.java.net/spring/core 
     http://jax-ws.dev.java.net/spring/core.xsd 
     http://jax-ws.dev.java.net/spring/servlet 
     http://jax-ws.dev.java.net/spring/servlet.xsd" 
> 

    <wss:binding url="/hello"> 
     <wss:service> 
      <ws:service bean="#helloWs"/> 
     </wss:service> 
    </wss:binding> 

    <!-- Web service methods --> 
    <bean id="helloWs" class="it.capgemini.HelloWorldWS"> 
     <property name="helloWorldBo" ref="HelloWorldBo" /> 
    </bean> 

    <bean id="HelloWorldBo" class="it.capgemini.soap.HelloWorlBoImpl" /> 

</beans> 

ありがとう!

+0

[春の構成](http://stackoverflow.com/questions/6283653/spring-configuration)の可能性の重複 – Dez

+0

http://stackoverflow.com/questions/39851336/spring-utilizing-mongo-implementation-over-jpa/39852442#39852442の編集が役立ちます。 – HARDI

答えて

2

Springは、JAX-WSサーブレットエンドポイント実装のための便利な基本クラス(SpringBeanAutowiringSupport)を提供します。 HelloServiceを公開するには、SpringのSpringBeanAutowiringSupportクラスを拡張し、ここでビジネスロジックを実装します。通常、ビジネスレイヤへの呼び出しを委任します。 SpringのマネージドBeanに対する依存関係を表現するために、Springの@Autowiredアノテーションを単に使用します。

@WebService(serviceName="hello") 
public class HelloServiceEndpoint extends SpringBeanAutowiringSupport { 
    @Autowired 
    private HelloService service; 

    @WebMethod 
    public void helloWs() { 
     service.hello(); 
    } 
} 

サービス自体:

public class HelloService { 
    public void hello() { 
     // impl 
    } 
} 

と設定

@Configuration 
public class JaxWsConfig { 

    @Bean 
    public ServletRegistrationBean wsSpringServlet() { 
     return new ServletRegistrationBean(new WSSpringServlet(), "/api/v10"); 
    } 

    @Bean 
    public HelloService helloService() { 
     return new HelloService(); 
    } 
} 
+0

コメントありがとうございました。 xml構成ファイルの代わりにこの2つのクラスを使用できますか? – bigghe

+0

はい、あなたのアプリに設定を追加する必要があります。 –

+0

WSSpringServlet()が見つかりません。SpringBoot 1.3.3です。 – bigghe

関連する問題