2013-12-22 53 views
9

我對Spring和Java在網上很新,一般來說,但我一直都在爲這個週末苦苦掙扎。將所有的配置集合在一起,讓Spring在IntelliJ本身上使用gradle是一個挑戰。Spring - Autowire java.lang.NoClassDefFoundError

我想在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

我的服務 -

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

} 

我的實現 -

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; 

    ..... 

} 

我的控制器 -

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

我一直在下面的建築物上Spring.io導遊RESTful服務以及a關於JavaCodeGeeks的幾篇文章(特別是 - http://www.javacodegeeks.com/2013/05/spring-jpa-data-hibernate-mysql-maven.html)。

任何幫助將不勝感激。

回答

23

您似乎錯過了aspectjweaver庫。你可以得到它here

+0

@Aventus任何時候當你得到一個'ClassNotFoundException'並且你不能識別這個類的名字時,只需要用'jar'這個詞來進行搜索。它通常會找到哪個庫,你可以找到類。 –

+3

我更感興趣的是爲什麼我需要aspectJ,我喜歡保持編織和其他'魔術'的最低限度,因爲它讓事情很難調試時,他們吹 - 相信我,我看到他們爆炸:( –