创建在类路径资源[applicationcontext.xml]中定义的名为“userservice”的bean时出错:

lx0bsm1f  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(262)
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

springtest.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();
    }
}

userservice.java和userserviceinpl.java

package com.spring.service;

public interface UserService {
    public void add();
    public void delete();
    public void update();
    public void query();
}
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"); 
    }
}

diypointcut.java文件

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

<?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>

所有spring framwork lib都在项目中导入。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题