aop:aspectj-autoproxy 在 applicationContext 上表现不佳



我是春天的初学者,我在使用aop:aspectj-autoproxy时遇到了问题,applicationContext.It 这让我感到困惑。 有目录映像: 目录 测试代码很简单,我省略了"import"语句

应用程序上下文.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>

记录器.java:

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

书店道.java:

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

书店道.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) {
}
}

书店服务.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:UsersqiangDesktopspringspring2outproductionspring2schema2managerBookShopDaoImpl.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:UsersqiangDesktopspringspring2outproductionspring2schema2managerBookShopDaoImpl.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

在应用程序上下文.xml,它变得没有问题,并且它已经失去了@before日志记录

我找到了答案,我没有检查过...

@Before("execution(* schema2.manager.*(..(("(

应更改为 @Before("execution(* schema.manager*.*(..(("(

而且我的项目库已经导入了整个目录的"aspectj/lib",我也不知道为什么它会导致问题,这很奇怪。

相关内容

  • 没有找到相关文章

最新更新