@Autowired Spring service not injected in a managed bean

隐身守侯 提交于 2019-12-13 04:09:52

问题


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>

来源:https://stackoverflow.com/questions/32553945/autowired-spring-service-not-injected-in-a-managed-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!