gpt4 book ai didi

java - aop :aspectj-autoproxy has worked bad at applicationContext

转载 作者:行者123 更新时间:2023-12-01 22:49:57 24 4
gpt4 key购买 nike

我是 Spring 的初学者,我在 applicationContext 中使用 aop:aspectj-autoproxy 时遇到问题。这让我很困惑。有目录图像: directory测试代码非常简单,我省略了'import'语句

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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<context:component-scan base-package="schema2.*" />
<aop:aspectj-autoproxy />

</beans>
<小时/>

Logger.java:

@Aspect
@Component
public class Logger{
@Before("execution(* schema2.manager.*(..))")
public void before(JoinPoint joinPoint){
System.out.println("The Method: " + joinPoint.getSignature().getName());
}
}

BookShopDao.java:

public interface BookShopDao{
int findBookPriceByIsbn(String isbn);
void updateBookStock(String isbn) throws RuntimeException;
void updateUserAccount(String username, int price);
}

BookShopDaoImpl.java:

@Repository("bookShopDao")
public class BookShopDaoImpl implements BookShopDao{
@Override
public int findBookPriceByIsbn(String isbn) {
return 0;
}
@Override
public void updateBookStock(String isbn) throws RuntimeException {
}
@Override
public void updateUserAccount(String username, int price) {
}
}

BookShopService.java:

public interface BookShopService {
void purchase(String book_isbn, String user_name);
}

BookShopServiceImpl.java:

@Service("bookShopService")
public class BookShopServiceImpl implements BookShopService{
@Override
public void purchase(String book_isbn, String user_name) {
}
}

启动.java

public class Start {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
BookShopService server = (BookShopService) context.getBean("bookShopService");
server.purchase("123", "John");
}
}

问题:

 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookShopDao' defined in file [C:\Users\qiang\Desktop\spring\spring2\out\production\spring2\schema2\manager\BookShopDaoImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: schema2.manager [Xlint:invalidAbsoluteTypeName]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookShopDao' defined in file [C:\Users\qiang\Desktop\spring\spring2\out\production\spring2\schema2\manager\BookShopDaoImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: schema2.manager [Xlint:invalidAbsoluteTypeName]

但是如果我删除

aop:aspectj-autoproxy

在applicationContext.xml中,它变得没有问题,并且它已经丢失了@before日志记录

最佳答案

我已经找到答案了,我没有仔细检查...

@Before("execution(* schema2.manager.*(..))") should be changed to @Before("execution(* schema.manager*.*(..))")

我的项目库已导入“aspectj/lib”整个目录,我也不知道为什么会导致问题,这很奇怪。

关于java - aop :aspectj-autoproxy has worked bad at applicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58460728/

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