Spring - Autowire java.lang.NoClassDefFoundError

时间:2013-12-22 03:18:07

标签: java spring hibernate

我对普通的网络上的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中定义名为“companyServiceImpl”的bean时出错   [JAR:文件:/Users/user/Documents/Project/demo/build/libs/demo-0.1.0.jar /demo/models/company/CompanyServiceImpl.class]:   bean的初始化失败;嵌套异常是   java.lang.NoClassDefFoundError:   组织/ 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();
    }
}

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

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:24)

您似乎错过了aspectjweaver库。你可以得到它here