Spring - Autowire java.lang.NoClassDefFoundError [英] Spring - Autowire java.lang.NoClassDefFoundError
问题描述
我在网上对Spring和Java非常陌生,但我一直在周末苦苦挣扎。将所有的配置集合在一起,让Spring在IntelliJ本身上使用gradle是一个挑战。
我试图在Spring中实现另一个项目,以便更好地理解如何使用它。
我整个上午都遇到了这个错误,并且在Spring上我经历了很多参考和指南,但是无法看到问题所在。
原因: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
我的服务 -
public interface CompanyService {
public Company create(Company company);
public Company delete(Long id)throws CompanyNotFoundException;
公开清单<公司>找到所有();
public公司更新(公司公司)抛出CompanyNotFoundException;
public Company findById(Long id);
$ / code>
我的实现 -
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import demo.exceptions.CompanyNotFoundException;
import javax.annotation.Resource;
import java.util.List;
@Service
公共类CompanyServiceImpl实现CompanyService {
@Resource
私有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 {
$ b $ @Autowired $ b $ private CompanyService companyService;
@RequestMapping(/ list)
public @ResponseBody
List< Company>公司(
){
return companyService.findAll();
$ / code $ / pre
我一直在关注Spring.io关于构建RESTful服务以及关于JavaCodeGeeks的一些文章(尤其是 - http://www.javacodegeeks.com/2013/05/spring-jpa-data-hibernate-mysql-maven.html )。
解决方案您好像缺少 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.
这篇关于Spring - Autowire java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!