Java 创建名为';用户服务';在类路径资源[applicationContext.xml]中定义:

Java 创建名为';用户服务';在类路径资源[applicationContext.xml]中定义:,java,spring,spring-mvc,Java,Spring,Spring Mvc,SpringTest.java Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [applicationContext.

SpringTest.java

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#a1a8d5' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#a1a8d5': Resolution of declared constructors on bean Class [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] from ClassLoader [sun.misc.Launcher$AppClassLoader@e2f2a] failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/JoinPoint
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#a1a8d5' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#a1a8d5': Resolution of declared constructors on bean Class [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] from ClassLoader [sun.misc.Launcher$AppClassLoader@e2f2a] failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/JoinPoint
UserService.java和userserviceinpl.java

package com.spring.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.spring.service.UserService;

public class SpringTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ApplicationContext apc = new ClassPathXmlApplicationContext("applicationContext.xml");
        
        UserService userService = (UserService) apc.getBean("userService");
        userService.add();
    }
}
Diypointcut.java

package com.spring.service;

public class UserServiceImpl implements UserService{

    @Override
    public void add() {
        // TODO Auto-generated method stub
        System.out.println("add a new user");
        
    }
    @Override
    public void delete() {
        // TODO Auto-generated method stub
        System.out.println("delete a new user");
    }
    @Override
    public void update() {
        // TODO Auto-generated method stub
        System.out.println("update user");
    }
    @Override
    public void query() {
        // TODO Auto-generated method stub
        System.out.println("query a new user"); 
    }
}
applicationContext.xml

package com.spring.diy;

public class Diypointcut {
    
    public void before() {
        System.out.println("before runing method!!!!!!");
    }
    
    public void after() {
        System.out.println("after runing method!!!!!!");
    }

}


所有Spring Framwork库都导入到project中。

请确认您的类路径中是否有此中列出的所有库。谢谢,它可以工作。未导入Spring AOP aspectjweaver-1.9.5.jar的其他依赖项。在spring framwork 5.2.9.RELEASE中没有aspectjweaver-1.9.5.jar.great。如果答案对你有帮助的话,也请投票。确认你的类路径中是否有列出的所有库。谢谢,它有效。未导入Spring AOP aspectjweaver-1.9.5.jar的其他依赖项。在spring framwork 5.2.9.RELEASE中没有aspectjweaver-1.9.5.jar.great。如果答案对你有帮助的话,也请投赞成票。
package com.spring.diy;

public class Diypointcut {
    
    public void before() {
        System.out.println("before runing method!!!!!!");
    }
    
    public void after() {
        System.out.println("after runing method!!!!!!");
    }

}
<?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:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       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.xsd">
                 
       <bean id="userService" class = "com.spring.service.UserServiceImpl"/>
       <bean id = "diy" class="com.spring.diy.Diypointcut"/>
       
       <aop:config>
          <aop:aspect ref="diy">
              <aop:pointcut expression="execution(* com.spring.service.UserServiceImpl.*(..))" id="point"/>
              <aop:before method="before" pointcut-ref="point"/>
              <aop:after method="after" pointcut-ref="point"/>
          </aop:aspect>
       </aop:config>
</beans>