I'm developping simple application with Spring using Spring Annotation, and I use Interface Repository for DAO Layer with @Repository and @Service for service layer. But the service class is not injected in the presentation layer and remains null.
this is the Repository interface :
@Repository
public interface DemandeRepository extends JpaRepository<Demande, Integer> {
}
this is the service layer:
public interface DemandeService {
public void addDemande(Demande demande) ;
}
@Service
public class DemandeServiceImp implements DemandeService {
@Autowired
private DemandeRepository demandeRepository;
public void addDemande(Demande demande) {
demandeRepository.save(demande)
}
}
and this is the managedbean
@Autowired
private DemandeService demandeService;
public void ajouterDemande(){
Demande demande = new Demande();
demande.setLibelle("demande1");
demandeService.addDemande(demande);
}
I declared the package witch contains the services in my ApplicationContext.xml
<context:component-scan base-package="com.projetweb.services"/>
Here is my faces-config.xml
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>