【问题标题】:Compile-time weaving based injection not working基于编译时编织的注入不起作用
【发布时间】:2013-06-18 10:28:55
【问题描述】:

一段时间以来,我一直在使用编译时编织来将一些 Spring 组件放入 Hibernate Search FieldBridge

@Configurable 
public class MultiLingualClassBridge implements FieldBridge,ParameterizedBridge { 

@Inject 
MessageSource messages; 

方面似乎得到了正确的编织(我反编译了类来检查)但是,在运行时,MessageSource 没有被注入。

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

我正在使用 Spring 3.1.2、Hibernate 4.2.2 和 Hibernate Search 4.3.0。我将 aspectj 从 1.6.11 升级到 1.7.2 无济于事。降级 Hibernate 似乎没有任何效果。 Tomcat 6 和 7 上也会发生同样的情况。

<context:spring-configured /> 

<context:annotation-config/> 

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

反编译的类(我尝试切换到注入 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");
      }

我已经尝试了很多东西,但现在我已经没有办法让它发挥作用了。有什么建议吗?

亲切的问候, 马克

【问题讨论】:

  • 你是说它曾经工作过,但经过一些升级后它停止工作或从未工作过?
  • 你见过这个问题吗 - stackoverflow.com/questions/901632/…?似乎是同一个问题。您是否将您的插件配置与帖子中的配置进行了比较?
  • 你现在的行为是什么?是否抛出异常?您可以为其他班级进行注射吗?
  • 成功了。不幸的是,由于这方面不起作用,回滚点尚不清楚。没有抛出异常,MessageSource 根本没有设置。我看到编译工作正常。我用反编译的 aop 东西编辑了我的帖子
  • 我猜它可能与类加载问题有关,因为我在包含 Spring MVC 部分和“核心”业务逻辑部分的项目上下文中使用它课堂是一部分。关于调试什么以获得更多见解有什么想法吗?

标签: hibernate aspectj hibernate-search aspectj-maven-plugin


【解决方案1】:

这似乎可以解决问题

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" depends-on="org.springframework.context.config.internalBeanConfigurerAspect">

【讨论】:

    猜你喜欢
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多