NullPointerException Autowired JSF + Spring Web con Anotaciones

272 views Asked by At

I have a web application with JSF + Spring but when I reference an Autowired object got an NullPointerException error.

My web.xml

     <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-context.xml</param-value>
</context-param>

 <!-- Spring Core-->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>

My spring-context.xml

<context:annotation-config/>

<context:component-scan base-package="pe.abc.defghi"/>

 <aop:aspectj-autoproxy />


<tx:annotation-driven/>

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/META-INF/settings.properties</value>
            </list>
        </property>
</bean>

<bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${driver}"/>
    <property name="url" value="${url}"/>
    <property name="username" value="${username}"/>
    <property name="password" value="${password}"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="persistenceUnitName" value="PU_JMAD"/>
</bean>

<bean class="org.springframework.orm.jpa.JpaTransactionManager"
    id="transactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

My interface:

public interface PerfilService {
public List<Perfil> buscar();     
public Perfil buscarXID(Integer id);
}

My Impl:

@Service("perfilService")
@Qualifier("impl1")
public class PerfilServiceImpl implements PerfilService {


@Override
public List<Perfil> buscar() {
           return null; 
}

@Override
public Perfil buscarXID(Integer id) {
            return null;
}     

}

My Bean:

@Component
@ManagedBean(name = "listados")
@ApplicationScoped
public class ListadoBean {

@Autowired
@Qualifier("impl1")
PerfilService perfilService;

public List<Perfil> getPerfiles() {
    perfiles = perfilService.buscar();
    return perfiles;
}

}

Error is produced when I call perfiles = perfilService.buscar(); because perfilService is null

0

There are 0 answers