I work on a maven multi module project. The modules are: the persistence module called entities
packaged as jar
, the services module called services
packaged as jar
and the web module called web
packaged as war
. The pom is the following:
<groupId>com.af</groupId>
<artifactId>eMuse</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>entities</module>
<module>services</module>
<module>web</module>
</modules>
Each module has his own application context file where I declare the beans.
entities-context.xml
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG">
<bean id="actionDAO" class="com.af.dao.impl.ActionDAOImpl" />
<bean id="milestoneDAO" class="com.af.dao.impl.MilestoneDAOImpl" />
<bean id="milestoneMarksDAO" class="com.af.dao.impl.MilestoneMarksDAOImpl" />
<bean id="milestoneTypeDAO" class="com.af.dao.impl.MilestoneTypeDAOImpl" />
<bean id="studentDAO" class="com.af.dao.impl.StudentDAOImpl" />
<bean id="studentsActionsDAO" class="com.af.dao.impl.StudentsActionsDAOImpl"></bean>
<bean id="teamDAO" class="com.af.dao.impl.TeamDAOImpl" />
<bean id="toolDAO" class="com.af.dao.impl.ToolDAOImpl" />
</beans>
services-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG">
<bean id="studentService" class="com.af.service.impl.StudentServiceImpl"/>
</beans>
Also in the services pom.xml
I added the dependency on the entities module.
<parent>
<groupId>com.af</groupId>
<artifactId>eMuse</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>services</artifactId>
<dependency>
<groupId>com.af</groupId>
<artifactId>entities</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
And the web module configuration file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU" xmlns:context="http://ift.tt/GArMu7"
xmlns:mvc="http://ift.tt/1bHqwjR" xmlns:p="http://ift.tt/1jdM0fE"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1CZCNBy
http://ift.tt/GArMu7 http://ift.tt/1tY3uA9
http://ift.tt/1bHqwjR http://ift.tt/YzZ6hD">
<mvc:annotation-driven />
<context:component-scan base-package="com.af" />
<import resource="classpath*:entities-context.xml"/>
<import resource="classpath*:services-context.xml"/>
<!-- Tiles configuration -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles2.TilesView</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<mvc:default-servlet-handler />
</beans>
web/pom.xml
<parent>
<groupId>com.af</groupId>
<artifactId>eMuse</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.af</groupId>
<artifactId>services</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.af</groupId>
<artifactId>entities</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- other dependencies-->
</dependencies>
And when i run:
@Controller
public class TestController {
@Autowired
private StudentService studentService;
@RequestMapping(value="/index", method = RequestMethod.GET)
public String test(Model model){
StudentModel stud = StudentModelMapper.mapStudentDTO(studentService.getStudentById(1));
model.addAttribute("name", stud.getFirstName());
return "index";
}
}
I get the exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.af.service.StudentService com.af.controller.TestController.studentService; nested exception is java.lang.NoClassDefFoundError: Lcom/af/dao/StudentDAO;
Can anyone tell me what i am doing wrong?
Aucun commentaire:
Enregistrer un commentaire