Announcement Announcement Module
No announcement yet.
Getting @Configurable to work Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:

    public class OwnerValidator {

    private Clinic clinic;

    public void setClinic(Clinic clinic){
    System.out.println("Autowiring worked."); = 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
    Here is a working example, hope it helps.

    public class Robot {
       private Service;	
       setService(Service service) {
    	// impl
    <bean class="" lazy-init="true" scope="prototype" depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
         <property name="service"     ref="service" />


    • #3

      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="" xmlns:xsi=""
      xmlns="" xmlns:aop=""
      xmlns:context="" xmlns:jee=""


      • #4

        take a look at 6.8. Using AspectJ with Spring applications


        • #5
          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
            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.