Я новичок весной, у меня проблема с использованием aop: aspectj-autoproxy в applicationContext. Это меня смутило. Имеется образ каталога: каталог Тестовые коды очень просты, Я пропустил оператор 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) {
}
}
Start.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 не становится проблемой, и он потерял @ перед регистрацией