こんにちは私はwebserviceを稼働しています。私はjax wsを使用しています。私はSpringを使用して、AutowiredでBeanを使用できるようにしました。その春はapplicationContext.xmlのプロパティ値注入のようなものです。JAX WS webserviceはapplicationcontextからSpring Beanを取得しないため、nullポインタ例外がスローされます
私は春のapplicationContext.xmlをエントリの下にいる:
@Autowired private MyBeanProperty myProperty;
をそして、私は方法があります:
<context:component-scan base-package="com.mybeans.service" />
<bean id="myProperty" class="com.mybeans.service.MyBeanProperty"
p:Size="BIG">
</bean>
ウェブサービスエンドポイントクラスでは、私が行っている
public String getSize() {
return myProperty.getSize();
}
を
残念ながら、私はメソッドを呼び出すときに値を取得せず、nullpointerexceptionをスローします。
PS:私はwebサービスのwsdlを実行するためにsoapUIを使用し、このメソッドを呼び出しました。
Webサービスは、BeanがSpringによって作成される前に実行されていますか?
はい、私はApplicationContextの中の成分のスキャンを使用しduffmoする
。そして、私はweb.xmlに以下のようなコンテキストローダーリスナーを持っています。ここで私はJAX-WSを使用しています
コードと春と私の完全なコードexplainaton ..です
を私を助けて、セットアップに私がビルドとしてMavenを使用しています のTomcat 7で実行する必要があるいくつかのWebサービスを試してみてくださいこのツールは、したがって、私はちょうどここに私の2つの依存関係リスト:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
を私のサービスクラスはcom.test.servicesに位置しており、TestService & HelloWorldServiceという名前で、次のように見ている:
package com.test.services;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(name = "Test", serviceName = "TestService")
public class TestService {
@WebMethod
public String getTest() {
return "Test";
}
}
これが私のweb.xmlです:
<?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">
<display-name>toolbox</display-name>
<description>testing webservices</description>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/testservice</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/helloworldservice</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
、これは私の日-jaxws.xmlです:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint
name="jaxws-servlet"
implementation="com.test.services.TestService"
url-pattern="/testservice"/>
<endpoint
name="jaxws-servlet"
implementation="com.test.services.HelloWorldService"
url-pattern="/helloworldservice" />
</endpoints>
これは素晴らしい作品と私はに私のブラウザを指していることにより、サービスにアクセスすることができます[ URL] http://localhost:8080/toolbox/testservice[/url] [URL] http://localhost:8080/toolbox/helloworldservice[/url]。 しかし、Springのサポートは明らかに有効化されていません。
私はちょうど利用できるHelloWorldServiceをリバー以下のことを試してみました: のweb.xml:
<?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">
<display-name>toolbox</display-name>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
とapplicationContext.xmlを:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
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-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan base-package="com.test.services" />
<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
<property name="baseAddress" value="http://localhost:8080/" />
</bean>
</beans>
さらに私は@Service注釈付きの両方のサービスクラスを注釈付き。前にも触れましたが、これはアルファベット順の最初のWebサービス、つまりHelloWorldServiceのみを公開します。 URLを変更すると、[url] http://localhost:8080/toolbox/helloworldservice[/url]ではなく[url] http://localhost:8080/[/url]として利用できるようになりました。 Tomcatのロギングは、Springコンテキストが両方のクラスをSpring Beanとしてロードすることを示しています。 両方のサービスを利用可能にしながら、Springサポートを有効にする方法についてのアイデアや提案はありますか?
これはすごくうれしくなりました。ありがとうございました。 @Autowiredはまだ動作しませんでしたが、コンポーネントスキャンが機能するので、私はアプリケーションコンテキストを使用してgetBean( "")メソッドを呼び出すことで対処しました。 –
Steer360