Domanda

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

È stato utile?

Soluzione

This seems to do the trick

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" depends-on="org.springframework.context.config.internalBeanConfigurerAspect">
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top