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
  • 87,898
  • 29
  • 167
  • 228
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,823
  • 2
  • 35
  • 42
  • Thanks for your immediately reply Mr.sudhakar..I tried it but still getting the same exception – Karthik Feb 22 '13 at 06:57
  • Hi mohan he s referring two different packages seperated by comma. – Karthik Feb 22 '13 at 07:14
  • Can you make sure you add all packages that use spring annotation to the tag, also can you post your applicationContext.xml and your package structure – Sudhakar Feb 22 '13 at 09:29
-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