java - Same resource in two different servlets -
is possible have same resource in 2 different classes in 2 different servlets?
i want this:
public class one{ @resource(name="subscriptionservice") private subscriptionservice subscriptionservice; } public class two{ @resource(name="subscriptionservice") private subscriptionservice subscriptionservice; } @service("subscriptionservice") @transactional public class subscriptionservice { }
there 2 different servlet class 1 , class 2 there 2 different instances of subscriptionservice. there way this?
edit:
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"> <!-- definition of root spring container shared servlets , filters --> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring/root-context.xml</param-value> </context-param> <!-- creates spring container shared servlets , filters --> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!-- processes application requests --> <servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring/appservlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name>member-ws</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>transformwsdllocations</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>member-ws</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> </web-app>
member-ws-servlet.xml
<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:sws="http://www.springframework.org/schema/web-services" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- dispatcherservlet context: defines servlet's request-processing infrastructure --> <!-- activates various annotations detected in bean classes --> <context:annotation-config /> <context:component-scan base-package="pl.pk.edu" /> <!-- uses latest feature 2.0.0 rc2. enables @endpoint , related spring-ws annotations. see spring ws reference 5.4--> <sws:annotation-driven /> <!--<context:component-scan base-package="pl.pk.edu" />--> <!-- saaj-specific implementation of webservicemessagefactory. wraps saaj messagefactory. factory use saaj 1.3 when found, or fall saaj 1.2 or 1.1. --> <beans:bean id="messagefactory" class="org.springframework.ws.soap.saaj.saajsoapmessagefactory"/> <!-- requires message factory declare 1 --> <beans:bean class="org.springframework.ws.transport.http.webservicemessagereceiverhandleradapter" p:messagefactory-ref="messagefactory"/> <!-- see reference @ beginning of document --> <beans:bean class="org.springframework.ws.transport.http.wsdldefinitionhandleradapter"/> <!-- responsible forwarding web service request correct adapters. similar spring mvc's dispatcherservlet --> <beans:bean id="messagedispatcher" class="org.springframework.ws.server.messagedispatcher"> <beans:property name="endpointadapters"> <beans:list> <beans:ref bean="defaultmethodendpointadapter"/> </beans:list> </beans:property> </beans:bean> <!-- see reference @ beginning of document --> <beans:bean class="org.springframework.web.servlet.handler.simpleurlhandlermapping"> <beans:property name="mappings"> <beans:value> /ws=messagedispatcher /ws/subscription.wsdl=subscription </beans:value> </beans:property> </beans:bean> <!-- see reference @ beginning of document --> <beans:bean class="org.springframework.web.servlet.mvc.simplecontrollerhandleradapter"/> <!-- uses latest feature 2.0.0 rc2. enables interceptor endpoints. see spring ws reference 5.5.2 here have interceptor validates xml request , logger --> <sws:interceptors> <beans:bean id="validatinginterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.payloadvalidatinginterceptor" p:schema="/web-inf/spring/wsservlet/subscription.xsd" p:validaterequest="true" p:validateresponse="true"/> <beans:bean id="logginginterceptor" class="org.springframework.ws.server.endpoint.interceptor.payloadlogginginterceptor"/> </sws:interceptors> <!-- uses latest feature 2.0.0 rc2. enables publishing of wsdl. see spring ws reference 3.7 dynamic location transformation work, special parameter must added web.xml. locationuri here has no use when integrated spring mvc because has been overriden simpleurlhandlermapping --> <sws:dynamic-wsdl id="subscription" porttypename="subscriptionport" locationuri="/" targetnamespace="http://www.example.org/subscription"> <sws:xsd location="/web-inf/spring/wsservlet/subscription.xsd"/> </sws:dynamic-wsdl> <!-- our mashaller. can use marshaller want. info on how use castor, see http://www.castor.org/xml-mapping.html#2.1-marshalling-behavior --> <beans:bean id="castormarshaller" class="org.springframework.oxm.castor.castormarshaller" p:mappinglocation="/web-inf/spring/wsservlet/castor-mapping.xml" /> <!-- use genericmarshallingmethodendpointadapter if read spring ws 2.0 api adapter: "deprecated. of spring web services 2.0, in favor of defaultmethodendpointadapter , marshallingpayloadmethodprocessor." see http://static.springsource.org/spring-ws/sites/2.0/apidocs/org/springframework/ws/server/endpoint/adapter/genericmarshallingmethodendpointadapter.html have implement using recommended implementation. advantage of these 2 classes have pluggable adapter. more info, check spring ws 2.0 api , source code. --> <beans:bean id="marshallingpayloadmethodprocessor" class="org.springframework.ws.server.endpoint.adapter.method.marshallingpayloadmethodprocessor"> <beans:constructor-arg ref="castormarshaller"/> <beans:constructor-arg ref="castormarshaller"/> </beans:bean> <beans:bean id="defaultmethodendpointadapter" class="org.springframework.ws.server.endpoint.adapter.defaultmethodendpointadapter"> <beans:property name="methodargumentresolvers"> <beans:list> <beans:ref bean="marshallingpayloadmethodprocessor"/> </beans:list> </beans:property> <beans:property name="methodreturnvaluehandlers"> <beans:list> <beans:ref bean="marshallingpayloadmethodprocessor"/> </beans:list> </beans:property> </beans:bean> </beans:beans>
servlet-context.xml
<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:web-services="http://www.springframework.org/schema/web-services" xsi:schemalocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- dispatcherservlet context: defines servlet's request-processing infrastructure --> <context:annotation-config /> <context:component-scan base-package="pl.pk.edu" /> <!-- enables spring mvc @controller programming model --> <annotation-driven /> <!-- handles http requests /resources/** efficiently serving static resources in ${webapproot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- wczytanie beansow dla tiles oraz plikow konfiguracyjnych --> <beans:bean class="org.springframework.web.servlet.view.tiles2.tilesviewresolver" /> <beans:bean class="org.springframework.web.servlet.view.tiles2.tilesconfigurer"> <beans:property name="definitions"> <beans:list> <beans:value>/web-inf/tiles.xml</beans:value> </beans:list> </beans:property> </beans:bean> <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/views directory --> <beans:bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <beans:property name="prefix" value="/web-inf/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> </beans:beans>
if subscriptionservice
defined in root-context.xml
should work.
therefore need modify component scan, that:
- the component scan in
root-context.xml
finds service notone
ortwo
no controller bean, and - the component scan 2 servlets find
one
/two
notsubscriptionservice
typicaly this done filtering (include , exclude )by annotations:
root-context.xml
:
<context:component-scan base-package="yourpackage"> <context:exclude-filter expression="org.springframework.stereotype.controller" type="annotation" /> </context:component-scan>
servlet-context.xml
:
<context:component-scan base-package="yourpackage" use-default-filters="false"> <context:include-filter expression="org.springframework.stereotype.controller" type="annotation" /> </context:component-scan>
Comments
Post a Comment