org.springframework.context.support.AbstractApplicationContext refresh
spring 项目启动报错:
4月 03, 2021 12:48:48 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘serviceImp’ defined in file [C:\Users\19165\IdeaProjects\spring_course\04_AOP_demo\target\classes\com\hrz\ba01\ServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: com.hrz.ba01 [Xlint:invalidAbsoluteTypeName]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘serviceImp’ defined in file [C:\Users\19165\IdeaProjects\spring_course\04_AOP_demo\target\classes\com\hrz\ba01\ServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: com.hrz.ba01 [Xlint:invalidAbsoluteTypeName]
报错原因 : 切入点表达式错误
源代码
@Aspect
@Component(value = "myAspect")
public class AspectJ_Demo {
@Before(value = "execution(* com.hrz.ba01.do*(..))")
public void printTime(){
System.out.println(new Date());
}
}
切入点表达式应改为:execution(* com.hrz.ba01.*.do*(..))
附录:切入点表达式
AspectJ 定义了专门的表达式用于指定切入点。表达式的原型是:
execution(modifiers-pattern? ret-type-pattern
declaring-type-pattern?name-pattern(param-pattern)
throws-pattern?)
解释:
modifiers-pattern] 访问权限类型
ret-type-pattern 返回值类型
declaring-type-pattern 包名类名
name-pattern(param-pattern) 方法名(参数类型和参数个数)
throws-pattern 抛出异常类型
?表示可选的部分
切入点表达式要匹配的对象就是目标方法的方法名。所以,execution 表达式中明显就是方法的签名。注意,表达式中黑色文字表示可省略部分,各部分间用空格分开。在其中可以使用以下符号:
符号 | 意义 |
---|---|
* | 0至多个任意字符 |
. . | 用在方法参数中 表示任意多个参数 ;用在包名后,表示当前包及其子包路径 |
+ | 用在类名后,表示当前类及其子类;用在接口后,表示当前接口及其实现类 |