Spring - Autowire java.lang.NoClassDefFoundError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20725901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:48:30  来源:igfitidea点击:

Spring - Autowire java.lang.NoClassDefFoundError

javaspringhibernate

提问by A23

I'm very new to Spring and Java on the web in the general but I've been struggling with this over the weekend. Getting all the configuration together and to get Spring working with gradle on IntelliJ itself was a challenge.

总的来说,我对网络上的 Spring 和 Java 非常陌生,但周末我一直在努力解决这个问题。将所有配置放在一起并使 Spring 与 IntelliJ 本身的 gradle 一起工作是一个挑战。

I'm trying to implement another one of my projects in Spring so that I may better understand how to work with it.

我正在尝试在 Spring 中实现我的另一个项目,以便我可以更好地了解如何使用它。

I've been getting this error all morning and I've gone through many references and guides on Spring but am unable to see what the problem is.

我整个早上都收到这个错误,我已经阅读了许多关于 Spring 的参考资料和指南,但我看不出问题是什么。

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private demo.models.company.CompanyService demo.models.company.CompanyController.companyService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyServiceImpl' defined in URL [jar:file:/Users/user/Documents/Project/demo/build/libs/demo-0.1.0.jar!/demo/models/company/CompanyServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable

引起:org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private demo.models.company.CompanyService demo.models.company.CompanyController.companyService; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:在 URL [jar:file:/Users/user/Documents/Project/demo/build/libs/demo-0.1.0. jar!/demo/models/company/CompanyServiceImpl.class]: bean 初始化失败;嵌套异常是 java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable

My service -

我的服务——

public interface CompanyService {
    public Company create(Company company);
    public Company delete(Long id) throws CompanyNotFoundException;
    public List<Company> findAll();
    public Company update(Company company) throws CompanyNotFoundException;
    public Company findById(Long id);

}

My implementation -

我的实施 -

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import demo.exceptions.CompanyNotFoundException;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CompanyServiceImpl implements CompanyService {

    @Resource
    private CompanyRepository companyRepository;

    .....

}

My controller -

我的控制器 -

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value="/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;


    @RequestMapping("/list")
    public @ResponseBody
    List<Company> company(
            ) {

        return companyService.findAll();
    }
}

I've been following the guides on Spring.io on building RESTful services as well as a few articles on JavaCodeGeeks (especially - http://www.javacodegeeks.com/2013/05/spring-jpa-data-hibernate-mysql-maven.html).

我一直在关注 Spring.io 上关于构建 RESTful 服务的指南以及一些关于 JavaCodeGeeks 的文章(特别是 - http://www.javacodegeeks.com/2013/05/spring-jpa-data-hibernate-mysql- maven.html)。

Any help would be greatly appreciated.

任何帮助将不胜感激。

采纳答案by Sotirios Delimanolis

You seem to be missing the aspectjweaverlibrary. You can get it here.

你似乎错过了aspectjweaver图书馆。你可以在这里得到它。