You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Shaowei Mao <sm...@amindsolutions.com> on 2006/07/31 21:59:05 UTC

[axis2] use spring configured bean inside axis2 as implementation class

Hi, I am trying to use spring configured bean by creating spring container
inside skeleton generated by wsdl2java to create my own implementation class
for web service, but spring container BeanFactory can't load my classes
packaged inside axis2 aar file. I think this is related to class loader
aixs2 is using for each web service. Does anyone have sample code to solve
this problem?

 

Shaowei Mao

aMind Solutions LLC

Phone: 425-313-3107

Email: smao@amindsolutions.com

website: www.amindsolutions.com

 


Re: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Rajith Attapattu <ra...@gmail.com>.
Hi Anderson,

Thanks for the feedback and I definitely appreciate it.
Once you are free please try out the fix by Dims to the class loading issue.
I guess that will take care of the main concern you have.

Also you don't have to expose your spring beans (the ones that implement the
business logic) directly to leverage the spring support.

also please see my comments inline.

Regards,

Rajith

On 8/3/06, Dave Andreasen < davea@knetica.com> wrote:
>
>   Hi Rajith,
>
>
>
> Here is how I am putting my application together.  I have a set of core
> services that are Spring beans.  I use Hibernate as my persistence tier.
> The Web services layer calls a Spring service that implements the business
> logic.
>
>
>
> Axis2's Spring support allows the developer to expose Spring beans as Web
> Services.  However, I don't really want to expose my Spring beans directly
> as Web Services.  My main motivation for this is that I can change the
> service interfaces without affecting my public Web services interface.  I
> can also hide some service interfaces that are used by other services but
> should not be publicly available (I could also just not expose them in the
> WSDL too).  I am also thinking it might help me with versioning down the
> road since I can have different Web service endpoints for different versions
> of my API.
>
[RA] You don't have to expose your spring beans (the ones that implement the
business logic) directly to leverage the spring support.

You could still have the WebService that calls your core spring beans (which
implements the business logic) as Spring beans. So you are not directly
exposing your business logic, but still you are using spring to wire your
web service with the spring beans that implement the business logic.

For example

public class MyWebService {

      private MyGreeting myGreeting;

      // let spring inject the dependency
      public void setMyGreeting(myGreeting){
          this.myGreeting = myGreeting;
      }

      public String greet(String name){
           return myGreeting.greetAccordingToTheTimeOfDay(name);
      }
}

//your business logic
public class MyGreetingImpl implements MyGreeting{

    public  String greetAccordingToTheTimeOfDay(String name){
        // if morning
           return "Good morning " + name:
       ....
    }

    public String greetWithLove(String name){
       // .....
   }
}

  My main issues with using Axis2 and Spring revolved around the Service
> classloader.  Spring likes to use the context classloader which does not
> have access to the resources deployed with the service.  I tried setting the
> classloader for Spring (one can set the classloader for the application
> context and the bean loader) but I ran into some problems with setting
> properties on Spring beans that I chalked up to permissions issues.  My
> current workaround is ugly but it works.  I deploy the Spring jars and the
> core services jar in the WEB-INF/lib for Axis2.  My service AAR just
> contains the Web Service skeletons.
>
>
>
> I do want to try the latest build.  The changes in the Service classloader
> look promising. Unfortunately I am going on vacation for a few days after
> today.  I am also trying to do a QA drop before I go so I am quite busy
> today.  That means I can't try the nightly build until late next week.  I
> would really like to not have to mess with the axis2.war so I am eager to
> try it out.
>
>
>
> Thanks for the quick response on the issue though.
>
>
>
> Dave
>  ------------------------------
>
> *From:* Rajith Attapattu [mailto:rajith77@gmail.com]
> *Sent:* Tuesday, August 01, 2006 7:50 PM
> *To:* axis-user@ws.apache.org; davea@knetica.com
> *Subject:* Re: [axis2] use spring configured bean inside axis2 as
> implementation class
>
>
>
> Anderson ,
>
> >I didn't use the extensions because they didn't apply to the approach we
> used for creating our Spring beans.  I did create an Axis module that loads
> my Spring >beans on Axis startup.
>
> Anderson if you don't mind I would like to hear about your use case about
> the spring bean creation. Perhaps we can improve our spring support based on
> your feedback.
>
> Regards,
>
> Rajith
>
> On 7/31/06, *Dave Andreasen* <da...@knetica.com> wrote:
>
> I had the same issue.  The problem is related to the Service using it's
> own classloader and Spring wanting to use the thread context classloader.
> See http://issues.apache.org/jira/browse/AXIS2-400.
>
>
>
> There have been some extensions made to support Spring in Axis2 in the
> nightly builds.  You try pulling them down to see if they help you out.
> Look at JIRA issue http://issues.apache.org/jira/browse/AXIS2-272 for more
> information
>
>
>
> I didn't use the extensions because they didn't apply to the approach we
> used for creating our Spring beans.  I did create an Axis module that loads
> my Spring beans on Axis startup.
>
>
>
> Hope this helps!
>
>
>
> Dave Andreasen
>
>
>  ------------------------------
>
> *From:* Shaowei Mao [mailto: smao@amindsolutions.com]
> *Sent:* Monday, July 31, 2006 2:59 PM
> *To:* axis-user@ws.apache.org
> *Subject:* [axis2] use spring configured bean inside axis2 as
> implementation class
>
>
>
> Hi, I am trying to use spring configured bean by creating spring container
> inside skeleton generated by wsdl2java to create my own implementation class
> for web service, but spring container BeanFactory can't load my classes
> packaged inside axis2 aar file. I think this is related to class loader
> aixs2 is using for each web service. Does anyone have sample code to solve
> this problem?
>
>
>
> Shaowei Mao
>
> aMind Solutions LLC
>
> Phone: 425-313-3107
>
> Email: smao@amindsolutions.com
>
> website: www.amindsolutions.com
>
>
>
>
>

RE: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Dave Andreasen <da...@knetica.com>.
Hi Rajith,

 

Here is how I am putting my application together.  I have a set of core
services that are Spring beans.  I use Hibernate as my persistence tier.
The Web services layer calls a Spring service that implements the business
logic.

 

Axis2's Spring support allows the developer to expose Spring beans as Web
Services.  However, I don't really want to expose my Spring beans directly
as Web Services.  My main motivation for this is that I can change the
service interfaces without affecting my public Web services interface.  I
can also hide some service interfaces that are used by other services but
should not be publicly available (I could also just not expose them in the
WSDL too).  I am also thinking it might help me with versioning down the
road since I can have different Web service endpoints for different versions
of my API. 

 

My main issues with using Axis2 and Spring revolved around the Service
classloader.  Spring likes to use the context classloader which does not
have access to the resources deployed with the service.  I tried setting the
classloader for Spring (one can set the classloader for the application
context and the bean loader) but I ran into some problems with setting
properties on Spring beans that I chalked up to permissions issues.  My
current workaround is ugly but it works.  I deploy the Spring jars and the
core services jar in the WEB-INF/lib for Axis2.  My service AAR just
contains the Web Service skeletons.

 

I do want to try the latest build.  The changes in the Service classloader
look promising. Unfortunately I am going on vacation for a few days after
today.  I am also trying to do a QA drop before I go so I am quite busy
today.  That means I can't try the nightly build until late next week.  I
would really like to not have to mess with the axis2.war so I am eager to
try it out.

 

Thanks for the quick response on the issue though.

 

Dave

  _____  

From: Rajith Attapattu [mailto:rajith77@gmail.com] 
Sent: Tuesday, August 01, 2006 7:50 PM
To: axis-user@ws.apache.org; davea@knetica.com
Subject: Re: [axis2] use spring configured bean inside axis2 as
implementation class

 

Anderson,

>I didn't use the extensions because they didn't apply to the approach we
used for creating our Spring beans.  I did create an Axis module that loads
my Spring >beans on Axis startup. 

Anderson if you don't mind I would like to hear about your use case about
the spring bean creation. Perhaps we can improve our spring support based on
your feedback.

Regards,

Rajith

On 7/31/06, Dave Andreasen <da...@knetica.com> wrote:

I had the same issue.  The problem is related to the Service using it's own
classloader and Spring wanting to use the thread context classloader.  See
http://issues.apache.org/jira/browse/AXIS2-400.  

 

There have been some extensions made to support Spring in Axis2 in the
nightly builds.  You try pulling them down to see if they help you out.
Look at JIRA issue http://issues.apache.org/jira/browse/AXIS2-272 for more
information

 

I didn't use the extensions because they didn't apply to the approach we
used for creating our Spring beans.  I did create an Axis module that loads
my Spring beans on Axis startup.  

 

Hope this helps!

 

Dave Andreasen

 

  _____  

From: Shaowei Mao [mailto:smao@amindsolutions.com] 
Sent: Monday, July 31, 2006 2:59 PM
To: axis-user@ws.apache.org
Subject: [axis2] use spring configured bean inside axis2 as implementation
class

 

Hi, I am trying to use spring configured bean by creating spring container
inside skeleton generated by wsdl2java to create my own implementation class
for web service, but spring container BeanFactory can't load my classes
packaged inside axis2 aar file. I think this is related to class loader
aixs2 is using for each web service. Does anyone have sample code to solve
this problem?

 

Shaowei Mao

aMind Solutions LLC

Phone: 425-313-3107

Email: smao@amindsolutions.com 

website: www.amindsolutions.com  <http://www.amindsolutions.com> 

 

 


Re: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Rajith Attapattu <ra...@gmail.com>.
Anderson,

>I didn't use the extensions because they didn't apply to the approach we
used for creating our Spring beans.  I did create an Axis module that loads
my Spring >beans on Axis startup.

Anderson if you don't mind I would like to hear about your use case about
the spring bean creation. Perhaps we can improve our spring support based on
your feedback.

Regards,

Rajith

On 7/31/06, Dave Andreasen <da...@knetica.com> wrote:
>
>  I had the same issue.  The problem is related to the Service using it's
> own classloader and Spring wanting to use the thread context classloader.
> See http://issues.apache.org/jira/browse/AXIS2-400.
>
>
>
> There have been some extensions made to support Spring in Axis2 in the
> nightly builds.  You try pulling them down to see if they help you out.
> Look at JIRA issue http://issues.apache.org/jira/browse/AXIS2-272 for more
> information
>
>
>
> I didn't use the extensions because they didn't apply to the approach we
> used for creating our Spring beans.  I did create an Axis module that loads
> my Spring beans on Axis startup.
>
>
>
> Hope this helps!
>
>
>
> Dave Andreasen
>
>
>  ------------------------------
>
> *From:* Shaowei Mao [mailto:smao@amindsolutions.com]
> *Sent:* Monday, July 31, 2006 2:59 PM
> *To:* axis-user@ws.apache.org
> *Subject:* [axis2] use spring configured bean inside axis2 as
> implementation class
>
>
>
> Hi, I am trying to use spring configured bean by creating spring container
> inside skeleton generated by wsdl2java to create my own implementation class
> for web service, but spring container BeanFactory can't load my classes
> packaged inside axis2 aar file. I think this is related to class loader
> aixs2 is using for each web service. Does anyone have sample code to solve
> this problem?
>
>
>
> Shaowei Mao
>
> aMind Solutions LLC
>
> Phone: 425-313-3107
>
> Email: smao@amindsolutions.com
>
> website: www.amindsolutions.com
>
>
>

Re: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Davanum Srinivas <da...@gmail.com>.
http://mail-archives.apache.org/mod_mbox/ws-axis-cvs/200608.mbox/%3c20060801175621.0C96C1A981A@eris.apache.org%3e
http://mail-archives.apache.org/mod_mbox/ws-axis-cvs/200608.mbox/%3c20060801182408.ADF611A981D@eris.apache.org%3e

-- dims

On 8/1/06, Shaowei Mao <sm...@amindsolutions.com> wrote:
> How did you fix it?
>
> -----Original Message-----
> From: Davanum Srinivas [mailto:davanum@gmail.com]
> Sent: Tuesday, August 01, 2006 11:34 AM
> To: axis-user@ws.apache.org; smao@amindsolutions.com
> Subject: Re: [axis2] use spring configured bean inside axis2 as
> implementation class
>
> Dave,Shaowei,
>
> If you pick up tonight's nightly, i've fixed this issue class loader
> problem and you won't need the hack.
>
> thanks,
> dims
>
> On 7/31/06, Shaowei Mao <sm...@amindsolutions.com> wrote:
> >
> >
> >
> >
> > Dave, thanks for info. I solved class loader problem by setting current
> > thread context class loader. This should work for me now.
> >
> >
> >
> >
> Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader(
> ));
> >
> >
> >
> >  ________________________________
> >
> >
> > From: Dave Andreasen [mailto:davea@knetica.com]
> >  Sent: Monday, July 31, 2006 1:11 PM
> >  To: axis-user@ws.apache.org; smao@amindsolutions.com
> >  Subject: RE: [axis2] use spring configured bean inside axis2 as
> > implementation class
> >
> >
> >
> >
> > I had the same issue.  The problem is related to the Service using it's
> own
> > classloader and Spring wanting to use the thread context classloader.  See
> > http://issues.apache.org/jira/browse/AXIS2-400.
> >
> >
> >
> > There have been some extensions made to support Spring in Axis2 in the
> > nightly builds.  You try pulling them down to see if they help you out.
> > Look at JIRA issue
> > http://issues.apache.org/jira/browse/AXIS2-272 for more
> > information
> >
> >
> >
> > I didn't use the extensions because they didn't apply to the approach we
> > used for creating our Spring beans.  I did create an Axis module that
> loads
> > my Spring beans on Axis startup.
> >
> >
> >
> > Hope this helps!
> >
> >
> >
> > Dave Andreasen
> >
> >
> >
> >  ________________________________
> >
> >
> > From: Shaowei Mao [mailto:smao@amindsolutions.com]
> >  Sent: Monday, July 31, 2006 2:59 PM
> >  To: axis-user@ws.apache.org
> >  Subject: [axis2] use spring configured bean inside axis2 as
> implementation
> > class
> >
> >
> >
> > Hi, I am trying to use spring configured bean by creating spring container
> > inside skeleton generated by wsdl2java to create my own implementation
> class
> > for web service, but spring container BeanFactory can't load my classes
> > packaged inside axis2 aar file. I think this is related to class loader
> > aixs2 is using for each web service. Does anyone have sample code to solve
> > this problem?
> >
> >
> >
> > Shaowei Mao
> >
> > aMind Solutions LLC
> >
> > Phone: 425-313-3107
> >
> > Email: smao@amindsolutions.com
> >
> > website: www.amindsolutions.com
> >
> >
> >
>
>
> --
> Davanum Srinivas : http://www.wso2.net (Oxygen for Web Service Developers)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Davanum Srinivas : http://www.wso2.net (Oxygen for Web Service Developers)

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Shaowei Mao <sm...@amindsolutions.com>.
How did you fix it?

-----Original Message-----
From: Davanum Srinivas [mailto:davanum@gmail.com] 
Sent: Tuesday, August 01, 2006 11:34 AM
To: axis-user@ws.apache.org; smao@amindsolutions.com
Subject: Re: [axis2] use spring configured bean inside axis2 as
implementation class

Dave,Shaowei,

If you pick up tonight's nightly, i've fixed this issue class loader
problem and you won't need the hack.

thanks,
dims

On 7/31/06, Shaowei Mao <sm...@amindsolutions.com> wrote:
>
>
>
>
> Dave, thanks for info. I solved class loader problem by setting current
> thread context class loader. This should work for me now.
>
>
>
>
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader(
));
>
>
>
>  ________________________________
>
>
> From: Dave Andreasen [mailto:davea@knetica.com]
>  Sent: Monday, July 31, 2006 1:11 PM
>  To: axis-user@ws.apache.org; smao@amindsolutions.com
>  Subject: RE: [axis2] use spring configured bean inside axis2 as
> implementation class
>
>
>
>
> I had the same issue.  The problem is related to the Service using it's
own
> classloader and Spring wanting to use the thread context classloader.  See
> http://issues.apache.org/jira/browse/AXIS2-400.
>
>
>
> There have been some extensions made to support Spring in Axis2 in the
> nightly builds.  You try pulling them down to see if they help you out.
> Look at JIRA issue
> http://issues.apache.org/jira/browse/AXIS2-272 for more
> information
>
>
>
> I didn't use the extensions because they didn't apply to the approach we
> used for creating our Spring beans.  I did create an Axis module that
loads
> my Spring beans on Axis startup.
>
>
>
> Hope this helps!
>
>
>
> Dave Andreasen
>
>
>
>  ________________________________
>
>
> From: Shaowei Mao [mailto:smao@amindsolutions.com]
>  Sent: Monday, July 31, 2006 2:59 PM
>  To: axis-user@ws.apache.org
>  Subject: [axis2] use spring configured bean inside axis2 as
implementation
> class
>
>
>
> Hi, I am trying to use spring configured bean by creating spring container
> inside skeleton generated by wsdl2java to create my own implementation
class
> for web service, but spring container BeanFactory can't load my classes
> packaged inside axis2 aar file. I think this is related to class loader
> aixs2 is using for each web service. Does anyone have sample code to solve
> this problem?
>
>
>
> Shaowei Mao
>
> aMind Solutions LLC
>
> Phone: 425-313-3107
>
> Email: smao@amindsolutions.com
>
> website: www.amindsolutions.com
>
>
>


-- 
Davanum Srinivas : http://www.wso2.net (Oxygen for Web Service Developers)

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Davanum Srinivas <da...@gmail.com>.
Dave,Shaowei,

If you pick up tonight's nightly, i've fixed this issue class loader
problem and you won't need the hack.

thanks,
dims

On 7/31/06, Shaowei Mao <sm...@amindsolutions.com> wrote:
>
>
>
>
> Dave, thanks for info. I solved class loader problem by setting current
> thread context class loader. This should work for me now.
>
>
>
> Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
>
>
>
>  ________________________________
>
>
> From: Dave Andreasen [mailto:davea@knetica.com]
>  Sent: Monday, July 31, 2006 1:11 PM
>  To: axis-user@ws.apache.org; smao@amindsolutions.com
>  Subject: RE: [axis2] use spring configured bean inside axis2 as
> implementation class
>
>
>
>
> I had the same issue.  The problem is related to the Service using it's own
> classloader and Spring wanting to use the thread context classloader.  See
> http://issues.apache.org/jira/browse/AXIS2-400.
>
>
>
> There have been some extensions made to support Spring in Axis2 in the
> nightly builds.  You try pulling them down to see if they help you out.
> Look at JIRA issue
> http://issues.apache.org/jira/browse/AXIS2-272 for more
> information
>
>
>
> I didn't use the extensions because they didn't apply to the approach we
> used for creating our Spring beans.  I did create an Axis module that loads
> my Spring beans on Axis startup.
>
>
>
> Hope this helps!
>
>
>
> Dave Andreasen
>
>
>
>  ________________________________
>
>
> From: Shaowei Mao [mailto:smao@amindsolutions.com]
>  Sent: Monday, July 31, 2006 2:59 PM
>  To: axis-user@ws.apache.org
>  Subject: [axis2] use spring configured bean inside axis2 as implementation
> class
>
>
>
> Hi, I am trying to use spring configured bean by creating spring container
> inside skeleton generated by wsdl2java to create my own implementation class
> for web service, but spring container BeanFactory can't load my classes
> packaged inside axis2 aar file. I think this is related to class loader
> aixs2 is using for each web service. Does anyone have sample code to solve
> this problem?
>
>
>
> Shaowei Mao
>
> aMind Solutions LLC
>
> Phone: 425-313-3107
>
> Email: smao@amindsolutions.com
>
> website: www.amindsolutions.com
>
>
>


-- 
Davanum Srinivas : http://www.wso2.net (Oxygen for Web Service Developers)

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Shaowei Mao <sm...@amindsolutions.com>.
Dave, thanks for info. I solved class loader problem by setting current
thread context class loader. This should work for me now.

 

Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader(
));

 

  _____  

From: Dave Andreasen [mailto:davea@knetica.com] 
Sent: Monday, July 31, 2006 1:11 PM
To: axis-user@ws.apache.org; smao@amindsolutions.com
Subject: RE: [axis2] use spring configured bean inside axis2 as
implementation class

 

I had the same issue.  The problem is related to the Service using it's own
classloader and Spring wanting to use the thread context classloader.  See
http://issues.apache.org/jira/browse/AXIS2-400.  

 

There have been some extensions made to support Spring in Axis2 in the
nightly builds.  You try pulling them down to see if they help you out.
Look at JIRA issue http://issues.apache.org/jira/browse/AXIS2-272 for more
information

 

I didn't use the extensions because they didn't apply to the approach we
used for creating our Spring beans.  I did create an Axis module that loads
my Spring beans on Axis startup.  

 

Hope this helps!

 

Dave Andreasen

 

  _____  

From: Shaowei Mao [mailto:smao@amindsolutions.com] 
Sent: Monday, July 31, 2006 2:59 PM
To: axis-user@ws.apache.org
Subject: [axis2] use spring configured bean inside axis2 as implementation
class

 

Hi, I am trying to use spring configured bean by creating spring container
inside skeleton generated by wsdl2java to create my own implementation class
for web service, but spring container BeanFactory can't load my classes
packaged inside axis2 aar file. I think this is related to class loader
aixs2 is using for each web service. Does anyone have sample code to solve
this problem?

 

Shaowei Mao

aMind Solutions LLC

Phone: 425-313-3107

Email: smao@amindsolutions.com

website: www.amindsolutions.com

 


RE: [axis2] use spring configured bean inside axis2 as implementation class

Posted by Dave Andreasen <da...@knetica.com>.
I had the same issue.  The problem is related to the Service using it's own
classloader and Spring wanting to use the thread context classloader.  See
http://issues.apache.org/jira/browse/AXIS2-400.  

 

There have been some extensions made to support Spring in Axis2 in the
nightly builds.  You try pulling them down to see if they help you out.
Look at JIRA issue http://issues.apache.org/jira/browse/AXIS2-272 for more
information

 

I didn't use the extensions because they didn't apply to the approach we
used for creating our Spring beans.  I did create an Axis module that loads
my Spring beans on Axis startup.  

 

Hope this helps!

 

Dave Andreasen

 

  _____  

From: Shaowei Mao [mailto:smao@amindsolutions.com] 
Sent: Monday, July 31, 2006 2:59 PM
To: axis-user@ws.apache.org
Subject: [axis2] use spring configured bean inside axis2 as implementation
class

 

Hi, I am trying to use spring configured bean by creating spring container
inside skeleton generated by wsdl2java to create my own implementation class
for web service, but spring container BeanFactory can't load my classes
packaged inside axis2 aar file. I think this is related to class loader
aixs2 is using for each web service. Does anyone have sample code to solve
this problem?

 

Shaowei Mao

aMind Solutions LLC

Phone: 425-313-3107

Email: smao@amindsolutions.com

website: www.amindsolutions.com