0

I get a null pointer exception when trying to inject an object. Here is my code:

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

ApplicationContext.XML

<bean id="accessDao" 
 Class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" 
  autowire-candidate="true">
  <property name="transactionManager" ref="txManager" />   
  <property name="target" ref="accessDaoTarget" />   
   <property name="transactionAttributes">   
   <props>   
  <prop key="*">PROPAGATION_REQUIRED</prop>   
   </props>   
  </property>   

</bean>   '

CommonBean

import com.domain.dao.IDao;
@Named
public class CommonBean implements Serializable{

/**
 * 
 */

private static final long serialVersionUID = 1L;
@Inject
private IDao accessDao;


public IDao getAccessDao()

      {
        return accessDao;
      }

 public void setAccessDao(IDao accessDao)
  {
    this.accessDao = accessDao;
  }

}
Buhake Sindi
  • 85,564
  • 27
  • 164
  • 223
Karthik
  • 21
  • 7

2 Answers2

0

The reason i suppose is because the component scan should include all the files that annotated by Spring. So for this to work , broaden the scope of packages to scan.

change from

<context:component-scan base-package="com.myjsf.appl.CommonBean" />

to

 <context:component-scan base-package="com.domain,com.myjsf" />
Sudhakar
  • 4,753
  • 2
  • 34
  • 42
-1

I think the reason is because you are refering to an "accessDao" bean which implements a IDAO interface. The bean accessDao declared on applicationContext.xml is of type org.springframework.transaction.interceptor.TransactionProxyFactoryBean which implements the BeanFactoryAware interface and NOT the IDAO interface.

As so spring will not recognize the bean you are trying to inject (IDAO accessDAO) and your property will not be initialized.

reis
  • 1