gpt4 book ai didi

java - Spring - java.lang.IllegalArgumentException

转载 作者:行者123 更新时间:2023-11-30 03:56:33 25 4
gpt4 key购买 nike

这让我抓狂 - 我研究并发现了具有类似错误的帖子,但似乎没有一个解决方案适合我。

输出:

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

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

<?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

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));

}
}

最佳答案

好吧,调用堆栈告诉你原因:

Initialization of bean failed; nested exception is
java.lang.IllegalArgumentException: warning no match for this type name:
coreservlets.aopaspj.service.DepartmentService [Xlint:invalidAbsoluteTypeName]

对我来说,看起来好像您在切入点之一中使用了像 Foo 这样的类名,但是 Spring-AOP 需要一个完全限定的类名,例如 com.blah.Foo。由于您还没有发布方面代码,因此很难说。我不是 Spring 用户,但这也是 AspectJ 中的一个常见陷阱,特别是如果您不使用 native 语法(您可以使用常规导入来缩短切入点中的类名)而是使用注释样式语法。后者需要完全限定的类名。

关于java - Spring - java.lang.IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23024907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com