1

I've been using compile-time weaving for a while now to get some spring components into a Hibernate Search FieldBridge:

@Configurable 
public class MultiLingualClassBridge implements FieldBridge,ParameterizedBridge { 

@Inject 
MessageSource messages; 

The aspect seems to get woven correctly (I decompiled the class to check) however, at runtime, the MessageSource doesn't get injected.

<plugin>
           <groupId>org.codehaus.mojo</groupId> 
            <artifactId>aspectj-maven-plugin</artifactId> 
            <version>1.4</version> 

            <executions> 
                <execution> 
                    <phase>process-classes</phase> 
                    <goals> 
                        <goal>compile</goal> 
                        <goal>test-compile</goal> 
                    </goals> 
                </execution> 
            </executions> 
            <dependencies> 
                <dependency> 
                    <groupId>org.aspectj</groupId> 
                    <artifactId>aspectjrt</artifactId> 
                    <version>${aspectj.version}</version> 
                </dependency> 
                <dependency> 
                    <groupId>org.aspectj</groupId> 
                    <artifactId>aspectjtools</artifactId> 
                    <version>${aspectj.version}</version> 
                </dependency> 
            </dependencies> 
            <configuration> 
                <source>1.6</source> 
                <target>1.6</target> 
                <verbose>true</verbose> 
                <complianceLevel>1.6</complianceLevel> 
                <encoding>UTF-8</encoding> 
                <showWeaveInfo>true</showWeaveInfo> 
                <forceAjcCompile>true</forceAjcCompile> 
                <aspectLibraries> 
                    <aspectLibrary> 
                        <groupId>org.springframework</groupId> 
                        <artifactId>spring-aspects</artifactId> 
                    </aspectLibrary> 
                </aspectLibraries> 
                <weaveDirectories> 
                    <weaveDirectory>${project.build.directory}/unwoven-classes</weaveDirectory> 
                </weaveDirectories> 

            </configuration> 

        </plugin>  

I'm working with Spring 3.1.2, Hibernate 4.2.2 and Hibernate Search 4.3.0. I upgraded aspectj from 1.6.11 to 1.7.2 to no avail. Downgrading Hibernate seems to have no effect. Same things occurs on Tomcat 6 and 7.

<context:spring-configured /> 

<context:annotation-config/> 

<context:component-scan 
    base-package="nl.project"/>  

Decompiled class (I tried switching to injecting a setMethod)

    @Configurable
    public class MultiLingualClassBridge
      implements FieldBridge, ParameterizedBridge, ConfigurableObject
    {
      MessageSource messages;

      static
      {
        ajc$preClinit();
      }

      public MultiLingualClassBridge()
      {
        JoinPoint localJoinPoint2 = Factory.makeJP(ajc$tjp_1, this, this); JoinPoint localJoinPoint1 = Factory.makeJP(ajc$tjp_0, this, this); if ((this != null) && (getClass().isAnnotationPresent(Configurable.class)) && (AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable)getClass().getAnnotation(Configurable.class)))) AnnotationBeanConfigurerAspect.aspectOf().ajc$before$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$1$e854fa65(this); if ((this != null) && (getClass().isAnnotationPresent(Configurable.class)) && ((this == null) || (!getClass().isAnnotationPresent(Configurable.class)) || (!AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable)getClass().getAnnotation(Configurable.class)))) && (AbstractDependencyInjectionAspect.ajc$if$6f1(localJoinPoint1))) AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);


        if ((!AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable)getClass().getAnnotation(Configurable.class))) && (AbstractDependencyInjectionAspect.ajc$if$6f1(localJoinPoint2))) AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);
      }

      @Inject
      public void setMessages(MessageSource messages)
      {
        this.messages = messages;
        log.info("MessageSource successfully registered");
      }

I've tried tons of things but now I've run out of ideas how to get this to work. Any suggestions?

Kind regards, Marc

Marc
  • 6,773
  • 10
  • 44
  • 68
  • Are you saying that is was working once, but after some upgrades it stopped working or has it never been working? – Hardy Jun 19 '13 at 08:51
  • Have you seen this question - http://stackoverflow.com/questions/901632/why-doesnt-aspectj-compile-time-weaving-of-springs-configurable-work? Seems to be the same issue. Have you compared your plugin configuration with the one in the post? – Hardy Jun 19 '13 at 09:08
  • And what is the behavior you get right now? Is there an exception thrown? Can you make injection work for another class? – Hardy Jun 19 '13 at 09:09
  • It has worked. unfortunately due to this aspect not working, the rollback point is not clear. There is no exception thrown, the MessageSource is simply not set. I see compilation working ok. I've edited my post with the decompiled aop stuff – Marc Jun 19 '13 at 14:04
  • I'm guessing it may have to do something with classloading issues as I'm using this in the context of a project that contains a Spring MVC part and a "core" business logic part of which this class is part. Any ideas on what to debug to get more insights? – Marc Jun 19 '13 at 14:10
  • Hmm, normally a class loading issue would throw some sort of exception. Debugging enhanced classes is of course also tricky, because your IDE sees different classes. I would try to find the Spring code which is responsible for the injection. Not sure which one is it, but there you would be able to see what is happening. – Hardy Jun 21 '13 at 13:11
  • Hmm, well I found the reason if not the root cause. The aspect is actually being found and processed. But when the AnnotationBeanConfigurerAspect is trying to configure the bean the beanFactory is still null. Not clear why. – Marc Jul 03 '13 at 12:36
  • In fact, I'm seeing the call to setBeanFactory on org.springframework.beans.factory.wiring.BeanConfigurerSupport occur *after* the configureBean has run as the Hibernate classbridge gets initiated. Now, how to get that fixed? – Marc Jul 03 '13 at 13:07

1 Answers1

0

This seems to do the trick

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" depends-on="org.springframework.context.config.internalBeanConfigurerAspect">
Marc
  • 6,773
  • 10
  • 44
  • 68