Results 1 to 6 of 6

Thread: Getting @Configurable to work

  1. #1

    Default Getting @Configurable to work

    I tried using the @Configurable annotation in the Spring petclinic example, but it's not working for me.

    In application-context-jdbc.xml, I added these lines:
    <context:annotation-config />
    <context:spring-configured />
    <context:load-time-weaver />

    In petclinic-servlet.xml I added component scanning of the validation package, because my configurable class is in that package. So now my component-scan snippets are:

    <!--Was already there -->
    <context:component-scan base-package="org.springframework.samples.petclinic.web "/>
    <!-- New -->
    <context:component-scan base-package="org.springframework.samples.petclinic.val idation" />

    (Notes: 1) For some reason 'validation' is formatted here so that there's a separation between the 'l' and the 'i', at least when viewed on my browser. That's not the case in the actual applicationContext. 2) I decided not to simply scan org.springframework.samples because that caused errors when the HibernateClinic expects a SessionFactory to be autowired, and I'm using the jdbc version of the petclinic for now.)


    I attempted to make OwnerValidator configurable. Here's the relevant code:

    @Configurable(dependencyCheck=true)
    public class OwnerValidator {

    private Clinic clinic;

    @Autowired
    public void setClinic(Clinic clinic){
    System.out.println("Autowiring worked.");
    this.clinic = clinic;
    System.out.println("Value of clinic is " + clinic);
    }

    Finally, I ran Tomcat from Eclipse, adding -javaagent:C:\spring-agent.jar to the end of the jvm argument string.

    Result: The Clinic was never autowired into the OwnerValidator.

    Any suggestions would be appreciated.

  2. #2
    Join Date
    Mar 2009
    Location
    Brazil
    Posts
    25

    Default

    Here is a working example, hope it helps.

    Code:
    @Configurable
    public class Robot {
    
       private Service;	
    
       setService(Service service) {
    	// impl
       }
    }
    Code:
    <aop:spring-configured/>
    
    <bean class="br.com.xxx.Robot" lazy-init="true" scope="prototype" depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
         <property name="service"     ref="service" />
    </bean>
    Regards
    Juliano

  3. #3

    Default @Configurable

    When I try adding <aop:spring-configured/> I get this exception on startup.

    org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:spring-configured'.

    Maybe there's some other part of your applicationContext that makes this work. Here's the xml header I'm using:

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Application context definition for PetClinic on JDBC.
    -->
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="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"
    xsi:schemaLocation="
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.5.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schem...ng-jee-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

  4. #4
    Join Date
    Mar 2009
    Location
    Brazil
    Posts
    25

    Default

    http://static.springframework.org/sp...rence/aop.html

    take a look at 6.8. Using AspectJ with Spring applications
    Regards
    Juliano

  5. #5

    Default Section 6.8 is not much help

    ... because it recomends <aop:spring-configured/> and, as I've mentioned in a previous post, that leads to this exception on startup:

    org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:spring-configured'.

  6. #6
    Join Date
    Nov 2006
    Posts
    26

    Default

    I hope you've already figured this out but you should reference the documentation for the version of Spring that you are using. In Spring 2.5 they moved spring-configured into the 'context' namespace.

    http://static.springsource.org/sprin...rence/aop.html

    Dustin

Posting Permissions

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