Problem definition
I have a Spring MVC project which is based on Gradle. I have a website project ( zeario-web
), a web crawler ( zeario-webcrawler
) and common classes ( zeario-sharedclientserverclasses
). The web and web crawler share some classes (something like DTO or VO).
In my web application, I have a CrawlerController
with the getWorkUnit
method; this calls the method on the CrawlerService
( @Autowired
depdency) instance, which in turn uses some classes from the shared library.
My problem is that I can create and deploy a working version of my web application using Gradle, but not through Eclipse. Eclipse gives me a Spring exception at runtime without the ability to search for one of the shared classes and, therefore, are unable to create / insert an instance of the service.
From Tomcat Logs:
org.springframework.beans.factory.BeanCreationException: Error creating bean named 'crawlerController': injection of auto-notified dependencies failed; The nested exception is org.springframework.beans.factory.BeanCreationException: Autofield failed: private com.zeario.service.CrawlerService com.zeario.api.v1.controller.CrawlerController.service; The nested exception is java.lang.NoClassDefFoundError: com / zeario / api / v1 / model / workunit / PageDiscoveryWorkUnit
Code snippets
Controller Definition (Simplified):
@Controller public class CrawlerController { @Autowired private CrawlerService service;
Class of service (simplified):
@Service public class CrawlerService { public PageDiscoveryWorkUnit getPageDiscoveryWorkUnit() { return new PageDiscoveryWorkUnit(); }
PageDiscoveryWorkUnit
is a simple POJO / Bean class. I have my beans service declared in spring-servlet.xml
:
<bean id="crawlerService" class="com.zeario.service.CrawlerService" />
Gradle Configuration
1) The root project (empty, without source) defines the subprojects in settings.gradle
. Dependencies are in build.gradle
:
project(':zeario-web') { dependencies { compile project(':zeario-sharedclientserver') } } project(':zeario-webcrawler') { dependencies { compile project(':zeario-sharedclientserver') } }
2) Projects determine dependencies on other projects, where applicable. For example, a web project build file contains:
dependencies { // Guava, Spring MVC, etc. ... packed project(':zeario-sharedclientserver') // Shared code // ... }
Eclipse Configuration
When I check build paths, Eclipse correctly displays project dependencies; for example, it shows that the web
project is dependent on the shared client/server
project.