0

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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
sad
  • 49
  • 1
  • 13
  • I doubt you are trying to use Spring MVC and JSF together or wrong configurations may be supposed. – Tiny Sep 13 '15 at 20:29
  • I don't use @Controller of Spring MVC, I have just jsf and managedbeans. – sad Sep 13 '15 at 20:32
  • `@Controller` is a valid usage while using JSF on top of Spring. – Tiny Sep 13 '15 at 20:35
  • but in my case I want to inject service interface in my managedbean but that doesn't work – sad Sep 13 '15 at 20:48
  • There could be some incorrect configurations. It is difficult to answer based on the information provided. – Tiny Sep 13 '15 at 20:53
  • Could you show your JSF configuration file contents? – Javier Haro Sep 13 '15 at 21:19
  • You forgot to tell who's managing the bean. Is it JSF via `@ManagedBean` or is it Spring via `@Component`? If JSF, then this is a duplicate: http://stackoverflow.com/questions/18387993/declaring-a-bean-as-managedbean-and-or-controller-in-order-to-inject-a-spring/ – BalusC Sep 14 '15 at 08:03

0 Answers0