Spring + aspectj - No unique bean of type

3 respostas
lelodois

Olá pessoal, bom dia.

Estou integrando spring com aspectj mas estou recebendo uma exceção de injeção de dependência de um bean meu.
Sem o aspectj não recebo esta exceção.

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:jee="http://www.springframework.org/schema/jee"
	xsi:schemaLocation="http://www.springframework.org/schema/beans   
                        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
                        http://www.springframework.org/schema/context   
                        http://www.springframework.org/schema/context/spring-context-2.5.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
                        http://www.springframework.org/schema/jee 
                        http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

	<!-- Spring annotation -->
	<aop:aspectj-autoproxy />
	<context:annotation-config />

	<!-- Hibernate Session Factory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSourceX" />
		<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
		<property name="configLocations" value="classpath:hibernate-config.cfg.xml" />
	</bean>

	<bean id="dataSourceX" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
         ...
	</bean>

	<!-- Gerenciamento de transações -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<bean id="transactionAttributes" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
		<property name="properties">
			<value>
				salvar*=PROPAGATION_REQUIRED
				*=PROPAGATION_REQUIRED,readOnly
			</value>
		</property>
	</bean>

	<!-- TransactionInterceptor -->
	<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributeSource" ref="transactionAttributes" />
	</bean>

	<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor</value>
			</list>
		</property>
		<property name="beanNames">
			<list>
				<value>*Service</value>
			</list>
		</property>
	</bean>

</beans>

Interceptor

package br.com.teste.interceptor;

import java.security.Principal;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import flex.messaging.FlexContext;
import flex.messaging.services.ServiceException;

@Aspect
@Component
public class  Interceptor {

	@Pointcut("@annotation(br.com.teste.Interceptor)")
	public void metodoa() {}

	@Before("metodoa()")
	public void antesdometodoa(JoinPoint joinPoint) {
		Signature signature = joinPoint.getSignature();
		System.err.println(signature.getName());
	}

	@After("metodoa()")
	public void depoisdometodoa(JoinPoint joinPoint) {}
}

Exception

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No unique bean of type [br.com.teste.TesteService] is defined: Unsatisfied dependency of type 
[class br.com.teste.TesteService]: expected at least 1 matching bean
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:613)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject
(AutowiredAnnotationBeanPostProcessor.java:412)	... 20 more

Alguém pode me ajudar?

3 Respostas

ivandasilva

Eu passei por um problemas desses recentemente, será que não tem nada a ver com o Proxy do Spring ? Faça a DI em cima de uma interface, eu acredito que funcione

lelodois

Velhinho… este erro ja foi resolvido, valeu.
Mas como nao lembro a resoluçao prefiro nao alterar o titulo…

Valeu,
Abraços

ivandasilva

Eu vi que o post era antigo mas, pensei, não custa ajudar!

Flw meu brother fica com Deus

Criado 15 de outubro de 2010
Ultima resposta 24 de mar. de 2011
Respostas 3
Participantes 2