2017-03-03 92 views
0

當我嘗試在同一個項目中使用時出現錯誤Spring Template JMS將消息傳遞給ActiveMQ和Spring AOP以審計和處理Weblogic上的異常12.2.1。服務器啓動時發生錯誤。在Weblogic 12.2.1上使用Spring AOP與JMS模板上的動態代理時出錯12.2.1

如果我配置方面使用CGLIB,我從Weblogic得到異常,我更喜歡,如果有可能保持使用動態代理。有沒有人有這個問題或有任何想法可能會導致它?

我的方面配置類:

@Configuration 
@EnableAspectJAutoProxy 
@lombok.extern.slf4j.Slf4j 
public class AspectConfig { 

    @Bean 
    public LoggingErrorAspect loggingErrorAspect(){ 
     return new LoggingErrorAspect(); 
    } 
} 

消息偵聽器配置類:

@Configuration 
@EnableJms 
@lombok.extern.slf4j.Slf4j 
public class MessagingListenerConfig { 

    @Autowired 
    ConnectionFactory connectionFactory; 

    @Bean 
    public JmsListenerContainerFactory<?> jmsListenerContainerFactory() { 
     DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); 
     factory.setConnectionFactory(connectionFactory); 
     factory.setConcurrency("1-1"); 
     return factory; 
    } 

} 

堆棧:

weblogic.application.ModuleEx ception: org.springframework.beans.factory.BeanNotOfRequiredTypeException:豆 名爲 'org.springframework.jms.config.internalJmsListenerEndpointRegistry' 預計 型 'org.springframework.jms.config.JmsListenerEndpointRegistry' 的但 實際上型「com.sun.proxy。$ Proxy213」

+0

我試圖改變到RabbitMQ的,但我得到了同樣的問題: 'weblogic.application.ModuleException:組織。 springframework.beans.factory.BeanNotOfRequiredTypeException:名爲'emailRabbitTemplate'的Bean預計爲'org.springframework.amqp.rabbit.core.Ra'類型bbitTemplate「,但實際上是類型'com.sun.proxy。$ Proxy182'' – antoniolazaro

回答

0

你不顯示你在哪裏注射JmsListenerEndpointRegistry(或RabbitTemplate),但你必須通過接口注入,當你代理與JDK代理。

你爲什麼建議註冊表 - 你想用什麼來實現?它不提供很多接口,因此一旦代理就不能被引用,除了DisposableBeanSmartLifecycle

RabbitTemplate可以代理,但您需要注入RabbitOperations而不是RabbitTemplate

+0

Gary,有沒有一些方法來定義方面只是與特定的類工作?我使用方面的主要目標是處理一般例外和審計一般操作。 – antoniolazaro

+0

您需要將切入點添加到您的方面以指定您希望應用的位置。查看'@ EnableAspectJAutoProxy'的javadocs和[Spring參考手冊](http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/aop.html)。 –

+0

謝謝你,加里羅素。我找到解決方案。 – antoniolazaro

0

我解決了它的問題。我必須將代理更改爲AMQP RabbitMQ,並且我需要在所有配置中使用接口而不是類。之後,啓動加載工作和方面也。

這裏是Aspect Config和Messaging Config。

AspectConfig:

@Configuration 
@EnableAspectJAutoProxy 
@lombok.extern.slf4j.Slf4j 
public class AspectConfig { 

    @Bean 
    public LoggingErrorAspect loggingErrorAspect(){ 
     return new LoggingErrorAspect(); 
    } 
} 

MessagingConfig:

@Configuration 
@PropertySources({ @PropertySource("classpath:/config/messaging.properties") }) 
@ComponentScan("br.com.aegea.scab.notification") 
@lombok.extern.slf4j.Slf4j 
public class MessagingConfig { 

    public static final String ERROR_QUEUE = "ERROR_QUEUE"; 
    public static final String EMAIL_QUEUE = "EMAIL_QUEUE"; 

    @Autowired 
    private Environment environment; 

    @Bean 
    public ConnectionFactory connectionFactory() { 
     CachingConnectionFactory connectionFactory = new CachingConnectionFactory(environment.getProperty("spring.rabbitMQ.host")); 
     connectionFactory.setUsername(environment.getProperty("spring.rabbitMQ.user")); 
     connectionFactory.setPassword(environment.getProperty("spring.rabbitMQ.password")); 
     return connectionFactory; 
    } 

    @Bean 
    public MessageConverter jsonMessageConverter() { 
     return new JsonMessageConverter(); 
    } 

    @Bean 
    public RabbitOperations emailRabbitTemplate() { 
     RabbitTemplate template = new RabbitTemplate(connectionFactory()); 
     template.setRoutingKey(EMAIL_QUEUE); 
     template.setMessageConverter(jsonMessageConverter()); 
     return template; 
    } 

    @Bean 
    public MessageListenerContainer listenerContainer() { 
     SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(); 
     listenerContainer.setConnectionFactory(connectionFactory()); 
     listenerContainer.setQueueNames(EMAIL_QUEUE); 
     listenerContainer.setMessageConverter(jsonMessageConverter()); 
     listenerContainer.setMessageListener(messageReceiver()); 
     listenerContainer.setAcknowledgeMode(AcknowledgeMode.AUTO); 
     return listenerContainer; 
    } 

    @Bean 
    public MessageListener messageReceiver() { 
     return new MessageReceiver(); 
    } 
} 
相關問題