Ciao, ho installato e funzionante il servizio web, ho usato jax ws. Ho usato Spring per essere in grado di utilizzare i bean con Autowired e roba che molla come un'iniezione del valore della proprietà in applicationContext.xml.JAX WS webservice non accetta il bean spring da applicationcontext, quindi genera un'eccezione di puntatore nullo
ho il seguito dell'entrata primavera applicationContext.xml:
<context:component-scan base-package="com.mybeans.service" />
<bean id="myProperty" class="com.mybeans.service.MyBeanProperty"
p:Size="BIG">
</bean>
Nel web classe punto finale del servizio, ho fatto:
@Autowired private MyBeanProperty myProperty;
E io ho un metodo:
public String getSize() {
return myProperty.getSize();
}
Sfortunatamente quando invoco il metodo non ottiene alcun valore e genera nullpointerexception.
PS: Ho usato soapUI per eseguire wsdl del servizio web e invocato il metodo.
Il webservice viene eseguito prima che i bean vengano creati entro la primavera ??
Per duffmo
Sì ho usato scansione componente applicationContext. E ho il listener del caricatore di contesto come di seguito in web.xml. Please help me ..
Ecco il mio explainaton codice completo con il codice di
Sto usando JAX-WS e la primavera e cercare di impostare un paio di WebServices che devono funzionare su Tomcat 7. sto usando Maven come costruire strumento quindi ho solo elencare i miei due dipendenze qui:
<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>
le mie classi di servizio sono situate in com.test.services e prendono il nome TestService & HelloWorldService e apparire come segue:
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";
}
}
questo è il mio 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>
e questo è il mio sole-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>
Questa grande opera e posso accedere ai servizi puntando il browser per [ url] http://localhost:8080/toolbox/testservice[/url] rispettivamente [url] http://localhost:8080/toolbox/helloworldservice[/url]. Tuttavia il supporto a molla non è ovviamente attivato.
Ho provato seguenti elementi appena licenziato della scuola media HelloWorldService disponibili: 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>
e 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>
inoltre ho annotato entrambe le classi di servizio con @Service annotazione. Come ho detto prima, questo pubblica solo il primo web service in ordine alfabetico, quindi HelloWorldService. Inoltre modifica l'URL, poiché il servizio è ora disponibile come [url] http://localhost:8080/[/url] anziché [url] http://localhost:8080/toolbox/helloworldservice[/url]. La registrazione di Tomcat mostra che il contesto di primavera carica entrambe le classi come bean Spring. Hai qualche idea o suggerimento su come abilitare il supporto Spring mantenendo entrambi i servizi disponibili ??
Ha funzionato alla grande ora, grazie. @Autowired continua a non funzionare, ma la scansione dei componenti funziona, quindi ho risolto il problema con l'utilizzo del contesto dell'applicazione e chiamando il metodo getBean (""). –
Steer360