[ERROR][TaskAgile] .NoUniqueBeanDefinitionException, import한 패키지와 같은 이름일 때
2020. 11. 30. 18:26ㆍ개발 관련/ERROR
이전 포스팅에서 같은 에러가 났다.
Error starting ApplicationContext.
To display the conditions report re-run your application with 'debug' enabled.
2020-11-30 17:33:28.392 ERROR 4344 ---
[lication.main()] o.s.b.d.LoggingFailureAnalysisReporter :
...
Description:
Parameter 2 of constructor in com.taskagile.domain.common.mail.DefaultMailManager required a single
bean, but 2 were found:
- getFreemarkerConfiguration:
defined by method 'getFreemarkerConfiguration' in class path resource
[com/taskagile/domain/common/mail/DefaultMailManagerTests$DefaultMessageCreatorConfiguration.class]
- freeMarkerConfiguration:
defined by method 'freeMarkerConfiguration' in class path resource
[org/springframework/boot/autoconfigure/freemarker/FreeMarkerServletWebConfiguration.class]
Action:
Consider marking one of the beans as @Primary,
updating the consumer to accept multiple beans,
or using @Qualifier to identify the bean that should be consumed
[WARNING]
java.lang.reflect.InvocationTargetException
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'userServiceImpl' defined in file
[C:\Users\ttogl\practice\TaskAgile\vuejs.spring-boot.mysql\target\classes\com\taskagile\domain\application\impl\UserServiceImpl.class]:
Unsatisfied dependency expressed through constructor parameter 2;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'defaultMailManager' defined in file
[C:\Users\ttogl\practice\TaskAgile\vuejs.spring-boot.mysql\target\classes\com\taskagile\domain\common\mail\DefaultMailManager.class]:
Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type 'freemarker.template.Configuration' available:
expected single matching bean but found 2:
getFreemarkerConfiguration,freeMarkerConfiguration
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray
(ConstructorResolver.java:732)
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'defaultMailManager' defined in file
[C:\Users\ttogl\practice\TaskAgile\vuejs.spring-boot.mysql\target\classes\com\taskagile\domain\common\mail\DefaultMailManager.class]:
Unsatisfied dependency expressed through constructor parameter 2;
nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type 'freemarker.template.Configuration' available:
expected single matching bean but found 2:
getFreemarkerConfiguration,freeMarkerConfiguration
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray
(ConstructorResolver.java:732)
...
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type 'freemarker.template.Configuration' available:
expected single matching bean but found 2:
getFreemarkerConfiguration,freeMarkerConfiguration
at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique
(DependencyDescriptor.java:215)
...
ERROR 내용
- com.taskagile.domain.common.mail.DefaultMailManager 에서 같은 타입의 bean이 2개 찾아져서 생긴 에러( getFreemarkerConfiguration, freeMarkerConfiguration )
- 하나는 import freemarker.template.Configuration했던 것이고, 다른 하나는 test클래스에 만들었던 getFreemarkerConfiguration이다.
해결 방법
- freemarker.template.Configuration을 사용할 것이기 때문에 정의할 때 패키지 전문을 다 붙이면 헷깔리지 않는다.
import freemarker.template.Configuration;
//...
@Component
public class DefaultMailManager implements MailManager {
private final static Logger log = LoggerFactory.getLogger(DefaultMailManager.class);
// ...
private freemarker.template.Configuration configuration;
public DefaultMailManager(@Value("${app.mail-from}") String mailFrom,
Mailer mailer,
freemarker.template.Configuration configuration) {
this.mailFrom = mailFrom;
this.mailer = mailer;
this.configuration = configuration;
}
참고 사이트 : dpdpwl.tistory.com/69