I am into a problem from two days and I can not get out from this.
The problem I am having is using a MangedBean property after the deserialization (I guess).
The property (purchaseManager) is set up with Spring, and use a DAO which extends MyBatis as data mapper to interact with the DB.
In fact, on the first access to the page, purchaseManager.getAll() inside init() method works fine.
When i try to call refreshList() as an action from a button, I have a NullPointerException on the getSqlSession() inside the DAO.
Letting only the relevant code the situation is as follow:
@ManagedBean(name = "purchaseController")
@ViewScoped
public class PurchaseController implements Serializable{
@ManagedProperty(value = "#{purchaseManager}")
private PurchaseManager purchaseManager;
@PostConstruct
public void init(){
purchaseManager.getAll();
}
public void refreshList(){
purchaseManager.getAll();
}
}
public class PurchaseManagerImpl implements PurchaseManager, Serializable {
PurchaseDAO purchaseDAO;
public void getAll() {
purchaseDAO.getAll()
}
}
public class PurchaseDAOImpl extends SqlSessionDaoSupport implements PurchaseDAO, Serializable {
public void getAll() {
SqlSession session = getSqlSession(); // when the call comes from refreshList(), session is null
session.selectList("PAYMENT.getAll", null);
}
}
in web.xml
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
If I change the STATE_SAVING_METHOD to server the application works fine but is not what I want. Same thing if I make the ManageBean as RequestScope but this too will penalize my requirements.
Thank you in advance to anyone for any kind of help! Ermal
@EJB
instead of@ManagedProperty
which will basically inject a fully serializable proxy instance. Does Spring really not have some annotation for that?@Autowired
or so? – Acyclic@Autowired
seems to be the solution to inject correctly the spring beans. Although, I have the error com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean purchaseController in the PurchaseController.init() method. My applications seems stabile only when using@ManagedProperty
. From your experience, what may cause an eventual issue in PRD environment with only@ManagedProperty
? – Grendel<aop:scoped-proxy proxy-target-class="false" />
in the Spring bean definition. Now that my manager/service object is defined as I said, thing are working fine. So my DB (MyBatis) reference is not null anymore. – Grendel