[英]Spring - java.lang.IllegalArgumentException
This is driving me nuts - I've researched and found posts with similar errors, but none of the solutions seem to be working for me. 这让我发疯了-我研究并发现了类似错误的帖子,但是似乎没有一种解决方案对我有用。
Output: 输出:
Apr 11, 2014 8:59:07 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3bb2b8: startup date
[Fri Apr 11 20:59:07 EDT 2014]; root of context hierarchy
Apr 11, 2014 8:59:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Apr 11, 2014 8:59:08 PM
org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@104c575: defining beans [departmentDAO,departmentService,securityAspect,org.springframework.aop.config.internalAuto ProxyCreator]; root of factory hierarchy
Apr 11, 2014 8:59:08 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in rg.springframework.beans.factory.support.DefaultListableBeanFactory@104c575: defining beans [departmentDAO,departmentService,securityAspect,org.springframework.aop.config.internalAutoProxyCreator]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'departmentDAO' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: coreservlets.aopaspj.service.DepartmentService [Xlint:invalidAbsoluteTypeName]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at coreservlets.aopaspj.ExerciseRunner.main(ExerciseRunner.java:11)
Caused by: java.lang.IllegalArgumentException: warning no match for this type name: coreservlets.aopaspj.service.DepartmentService [Xlint:invalidAbsoluteTypeName]
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:317)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:204)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:191)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:172)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:198)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:252)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:284)
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:359)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:404)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
... 11 more
SecurityAspect.java SecurityAspect.java
package coreservlets.aopaspj.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import coreservlets.aopaspj.exception.InvalidEmployeeException;
@Aspect
public class SecurityAspect {
@SuppressWarnings("unused")
@Pointcut("execution(* coreservlets.aopaspj.service.DepartmentService.getDepartment(..) )")
private void getDepartmentPointcut(){}
@Before("getDepartmentPointcut() && args(employeeId, lastName)")
public void verifyEmployee(long employeeId, String lastName) throws InvalidEmployeeException {
if (!((employeeId == 1) && lastName.equals("Smith") || (employeeId == 2) && lastName.equals("Jones"))) {
throw new InvalidEmployeeException();
}
}
}
applicationContext.xml applicationContext.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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="departmentDAO" class="coreservlets.aopaspj.dao.DepartmentDAOImpl" />
<bean id="departmentService"
class="coreservlets.aopaspj.service.DepartmentServiceImpl">
<property name="departmentDAO" ref="departmentDAO" />
</bean>
<bean id="securityAspect" class="coreservlets.aopaspj.aspect.SecurityAspect" />
<aop:aspectj-autoproxy/>
ExerciseRunner.java ExerciseRunner.java
package coreservlets.aopaspj;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import coreservlets.aopaspj.service.DepartmentServiceImpl;
public class ExerciseRunner {
public static void main(String[] args) {
ApplicationContext springContext = new ClassPathXmlApplicationContext("applicationContext.xml");
DepartmentServiceImpl departmentService =
springContext.getBean("departmentService", DepartmentServiceImpl.class);
long employeeId = 1;
String lastName = "Smith";
System.out.println(departmentService.getDepartment(employeeId, lastName));
}
}
Well, the callstack is telling you the reason: 好吧,调用堆栈告诉您原因:
Initialization of bean failed; nested exception is
java.lang.IllegalArgumentException: warning no match for this type name:
coreservlets.aopaspj.service.DepartmentService [Xlint:invalidAbsoluteTypeName]
To me it looks as if you use a class name like Foo
in one of your aspect pointcuts, but Spring-AOP expects a fully-qualified one like com.blah.Foo
. 在我看来,您似乎在一个方面切入点中使用了像
Foo
这样的类名,但是Spring-AOP希望使用像com.blah.Foo
这样的完全合格的类com.blah.Foo
。 As you have not posted your aspect code, this is hard to tell. 由于您尚未发布方面代码,因此很难分辨。 I am not a Spring user, but it is a common pitfall in AspectJ too, especially if you do not use native syntax (where you can use regular imports to shorten class names in pointcuts) but annotation-style syntax.
我不是Spring用户,但是这也是AspectJ中的一个常见陷阱,特别是如果您不使用本机语法(可以使用常规导入来缩短切入点中的类名),而是使用注释样式的语法。 The latter wants fully-qualified class names.
后者需要完全限定的类名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.