且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring - Autowire java.lang.NoClassDefFoundError

更新时间:2023-09-20 22:26:04

您好像缺少 aspectjweaver 库。您可以此处


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.

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

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.

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

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).

Any help would be greatly appreciated.

You seem to be missing the aspectjweaver library. You can get it here.