gpt4 book ai didi

java.lang.IllegalArgumentException : warning no match for this type name: UserDaoImpl [Xlint:invalidAbsoluteTypeName]

转载 作者:行者123 更新时间:2023-12-01 10:09:50 27 4
gpt4 key购买 nike

我正在开发一个基于 Spring 3.0.2 的项目。从过去三天开始,它显示以下错误。

java.lang.IllegalArgumentException: warning no match for this type name: UserDaoImpl [Xlint:invalidAbsoluteTypeName]

我该如何解决这个错误?

我的 applicationContext 文件是:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

<aop:aspectj-autoproxy/>
<context:component-scan base-package="web"/>
<!-- <import resource="appicationContext.xml"/> -->

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="jsp/" p:suffix=".jsp" />

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />


<bean id="sessionFactory" class="hibernatefiles.HibernateUtil" factory-method="getSessionFactory"/>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="userDaoImpl" class="dao.UserDaoImpl"/>

<bean id = "profiler" class = "Profiler.AspectProfiler" />

<bean name="/userRegistration.htm" class="web.UserController" depends-on="userDaoImpl">
<property name="userDaoImpl" ref="userDaoImp"/>
</bean>
</beans>

堆栈跟踪是:

   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController' defined in file [D:\JAVA Stuffs\projects\NewSpringDemo\build\web\WEB-INF\classes\web\UserController.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: **UserDaoImpl [Xlint:invalidAbsoluteTypeName]**
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:662)
root cause

java.lang.IllegalArgumentException: warning no match for this type name: UserDaoImpl [Xlint:invalidAbsoluteTypeName]
org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:204)
org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:191)
org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:172)
org.springframework.aop.support.AopUtils.canApply(AopUtils.java:200)
org.springframework.aop.support.AopUtils.canApply(AopUtils.java:254)
org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:286)
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117)
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359)
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1418)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:662)
...

userDaoImpl Autowiring 在带有 @Controller 注释的 UserController 类中:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package web;

import dao.UserDaoImpl;
import domain.UsersTable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

/**
*
* @author amit
*/

@Controller
@RequestMapping("/userRegistration.htm")
@SessionAttributes("user")
public class UserController {

@Autowired
private UserDaoImpl userDaoImpl;

public UserDaoImpl getUserDaoImpl() {
return userDaoImpl;
}

public void setUserDaoImpl(UserDaoImpl userDaoImpl) {
this.userDaoImpl = userDaoImpl;
}

@RequestMapping(method = RequestMethod.GET)
public String showForm(ModelMap model) {
System.out.println("Get request found. . . . *****************************");
UsersTable user = new UsersTable();
model.addAttribute("user", user);
return "registrationForm";
}

@RequestMapping(method = RequestMethod.POST)
public ModelAndView OnSubmit(@ModelAttribute("user") UsersTable user) {
System.out.println("User Object is : "+user);
userDaoImpl.saveUser(user);
return new ModelAndView("userConfirm", "user", user);
}
}

方面分析器:

package Profiler;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class AspectProfiler {
@Pointcut("execution(* UserDaoImpl.mySave())")
public void insertionProfiler(){ }

@Around("insertionProfiler()")
public void aroundInsertionProfiler(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("Before Insertion....");
pjp.proceed();
System.out.println("After saving the data I am back.");
}

}

最佳答案

我不知道为什么今天我的 RSS 提要上出现了这个老问题,但为了记录,正确的答案是,在注释样式的 AspectJ 切入点中,您需要使用完全限定的类名 < strong>包括包名,即切入点应该是

@Pointcut("execution(* dao.UserDaoImpl.mySave())")

这就是 [Xlint:invalidAbsoluteTypeName] 首先暗示的意思。

我想知道为什么在 2011 年没有其他人注意到这一点。


更新:在一种情况下,您可能不需要指定完全限定的类名 (FQCN):如果切面恰好与所使用的类或注释位于完全相同的包中在切入点。但这很脆弱,因为如果你重构,在包之间移动类,方面仍然可以编译,但它的行为会中断。所以你最好使用 FQCN,让你的 IDE 帮助你重构类和包名的变化,与切面同步。

关于java.lang.IllegalArgumentException : warning no match for this type name: UserDaoImpl [Xlint:invalidAbsoluteTypeName],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6315948/

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