• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Struts2.1.8 Spring3.2.1 anootated app with autowired, gives Service as NULL

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Spent the past day or so trying to set up a little Struts2, Spring3 (eventually Hibernate4) app with Annotations eg @autowired
but am having a little trouble.

For some reason my Action is always dropping to teh error.jsp, because my TestService is NULL.
Just wondering if anyone can see an obvioius reason why this is the case. I think I have included everything I need to below...








I'm sure it's going to turn out to be something stupid...

Thanks in advance

KS
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TestAction where you are Autowiring in your service is not a spring bean. Autowiring can only occur in Spring managed beans.

If you plan to use Struts 2 with Spring then I suggest you take a look at using the Struts 2 plugin for Spring.
http://struts.apache.org/development/2.x/docs/spring-plugin.html
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting.

I have the spring-struts-plugin.jar but guess I'm not using it properly.

Another interesting read I just found is this, not tried any of it yet though.

http://www.ibm.com/developerworks/library/j-sr2/index.html

Cheers for the input.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a really old thread and probably pertains to Struts 1. Struts 1 support is built into Spring. If you want to use Struts 2 then you should use the plugin I referred to earlier.


I don't see the plugin in your listed dependencies.

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.8</version>
</dependency>


Have a look at this tutorial
http://www.dzone.com/tutorials/java/struts-2/struts-2-example/struts-2-spring-plugin-integration-1.html

Note you don't need to wire your bean up in XML you are fine with the component scan like you have your bean name by convention will be "testService". However you can override this by giving a different name to the annotation @Service("myService")

Here was how someone else did it
http://stackoverflow.com/questions/9446176/struts2-spring-plugin-dependency-injection-with-annotated-actions-does-not-work

I think you should carefully read over the fist link I gave you again. I think you are missing something in the configuration. I don't use Struts 2 and Spring so I can provide much more assistance with this. I did add this to our Struts forum in case someone there has more experience integrating these 2 technologies.
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arh yes it works with the struts2-spring.2.3.8.jar I had the 'reverse' jar spring-struts2.jar

Cheers!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic