java.lang.IllegalArgumentException:警告与此类型名称不匹配:ru.sbt.filial.cards.aspect.SomeBean [Xlint:invalidAbsoluteTypeName]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21676860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.IllegalArgumentException: warning no match for this type name: ru.sbt.filial.cards.aspect.SomeBean [Xlint:invalidAbsoluteTypeName]
提问by Dmitry Bakhtiarov
I never used Spring AOP and trying to configure my first bean. It seems that I configured it properly, but I get an exception that the bean is not found.
我从未使用过 Spring AOP 并尝试配置我的第一个 bean。似乎我正确配置了它,但我收到一个异常,即找不到 bean。
My aspect is –
我的方面是——
@Aspect
@Component
public class IdentificationAspect {
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean.*(..))")
public void logBefore(JoinPoint joinPoint) throws Throwable {
System.out.println("logBefore() is running!");
System.out.println("hiHymaned : " + joinPoint.getSignature().getName());
System.out.println("******");
}
}
And my bean that AOP doesn't find is -
而我的 AOP 找不到的 bean 是 -
package ru.sbt.filial.cards.aspect;
import org.springframework.stereotype.Component;
@Component
public class SomeBean {
public void printSmth() {
System.out.println("!!!!!!!!!!!");
}
}
I've got the following exception -
我有以下例外 -
Caused by: java.lang.IllegalArgumentException: warning no match for this type name: ru.sbt.filial.cards.aspect.SomeBean [Xlint:invalidAbsoluteTypeName]
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getFallbackPointcutExpression(AspectJExpressionPointcut.java:358)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:255)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:208)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:356)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:319)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:412)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1629)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:162)
... 165 more
I have following maven dependencies -
我有以下 Maven 依赖项 -
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
And my spring applicationContext.xml configuration is -
我的 spring applicationContext.xml 配置是 -
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<mvc:annotation-driven/>
<aop:aspectj-autoproxy/>
<bean id="someBean" class="ru.sbt.filial.cards.aspect.SomeBean">
</bean>
UPDATEI added to my Spring configuration line
更新我添加到我的 Spring 配置行
<context:component-scan base-package="ru.sbt.filial.cards.aspect"/>
but still same message. I also tried to annotate different ways - if I don't specify the bean i.e. write -
但仍然是相同的信息。我也尝试以不同的方式注释 - 如果我不指定 bean ie write -
@Before("execution(* ru.sbt.filial.cards.aspect.*.*(..))")
instead
反而
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean.*(..))")
I have no error on loading, but aop method is not invoked.
我在加载时没有错误,但是没有调用 aop 方法。
I also tried to annotate like this
我也尝试这样注释
@Before("this(ru.sbt.filial.cards.aspect.SomeBean) and execution(* printSmth(..))")
but with same result - no match for this type name. Any more ideas??
但结果相同 - 与此类型名称不匹配。还有什么想法??
回答by Abhishek Nayak
To run successfully, In your spring applicationContext.xml configuration file add
要成功运行,在您的 spring applicationContext.xml 配置文件中添加
<context:component-scan base-package="ru.sbt.filial.cards.aspect"/>
As you used @Component
annotation in SomeBean class
当您@Component
在 SomeBean 类中使用注释时
Update:
更新:
try by adding method name to @Before:
尝试将方法名称添加到@Before:
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean.logBefore(..))")
回答by Daniel
I have the same problem as you and I've solved mine. I give you two suggestions, you can try it out. Please modify the @Before annotation in the aspect class as one of the following:
我和你有同样的问题,我已经解决了我的问题。我给你两个建议,你可以试试。请将方面类中的@Before 注释修改为以下之一:
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean.logBefore(..))")
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean.logBefore(..))")
or
或者
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean..*(..))")
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean..*(..))")
Hope it helps.
希望能帮助到你。
回答by s7raybird
you lose the class.
你丢了课。
@Before("execution(* ru.sbt.filial.cards.aspect.**SomeBean.***(..))")
@Before("execution(* ru.sbt.filial.cards.aspect.**SomeBean.***(..))")
In your way, "somebean" is a package, the * after it is a method, and you should put classes between them. You can do it like
以您的方式,“somebean”是一个包,它后面的 * 是一个方法,您应该在它们之间放置类。你可以这样做
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean.* .*(..))")
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean.* .*(..))")
or
或者
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean..*(..))")
@Before("execution(* ru.sbt.filial.cards.aspect.SomeBean..*(..))")