Results 1 to 4 of 4

Thread: How to autowire a bean loaded by Hibernate?

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    104

    Default How to autowire a bean loaded by Hibernate?

    Hi, I'm using Spring 3.1.0.RELEASE. One of my Hibernate classes (EventFeed) references a class (AbstractEventParser ), in which I'd like to get access to a service, loaded by Spring. However, my autowiring is failing (the service is always null). I'm trying ...

    Code:
    @Configurable
    public abstract class AbstractEventParser {
    
    	@Autowired
    	protected NetUtilsService netUtilsService;
    And my service class has

    Code:
    @Service("netUtilsService")
    public final class NetUtilsServiceImpl implements NetUtilsService {
    but the netUtilsService member field is always null in the AbstractEventParser class above. What do I have to do to successfully autowire the field in the "AbstractEventParser" class? I have verified that my applicationContext.xml scans the class ...

    Code:
    	<mvc:annotation-driven />
    	<context:component-scan base-package="com.myco.myproject" />
    Thanks, - Dave

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    I suggest a read of the reference guide. Basically, as you already noticed, your @Configurable is pretty much useless, there is nothing which knows what to do with that annotation. You need to add a context:spring-configured which enables the @Configurable, depending on your environment you need additional configuration, I suggest a read of the reference guide.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Apr 2010
    Posts
    104

    Default

    I was trying to follow the instructions here -- http://static.springsource.org/sprin...rence/aop.html, but before I go crazy, is there another way I should be doing this that is simpler to configure than the aspect-oriented angle?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    No... As you need it to be woven in the class. You want injection when an object is constructed and outside of spring and as such you need additional capabilities.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •