Search This Blog

Thursday, 26 September 2013

Method Injection in Spring

I knew Spring supports two types of injection - setter and constructor. I had also heard of a third type called method injection. But having never come across a use case for the same, I pretty much ignored it. Until I gave an interview.
All was going well until this question came along:
"You have a singleton bean. Is there a way to inject a new bean X into this class whenever you call the getX property of this bean ?"
I was pretty flummoxed. Later on I hunted on the web and came across this post by Rod Johnson.
The below post is an adaption from the same to focus on the interviewer's question.

Friday, 20 September 2013

The c namespace

With the growth of annotations XML configuration files continue to reduce in size (In some cases they have disappeared). I have never really been a fan of Annotations, especially those that bring in information that was best left outside Java code.

Monday, 16 September 2013

BeanFactory and Inheritance

Inheritance of Beans is a feature available in Spring Bean Factories. I decided to try the same using Spring's BeanFactory.

Saturday, 14 September 2013

Hibernate's custom annotations

In the previous few posts we saw how JPA provides us with an annotation driven approach to configure our entities. As with all standard APIs, when vendors implemented JPA, they found that the annotations did not cover every nifty trick provided by the implementations.

Monday, 9 September 2013

Different Message Formats in Spring MVC

In an earlier post we saw how Spring depended on MessageConverters to convert the request stream to java object and also the java objects to appropriate response formats.
As we had defined a Jackson converter, our controller's return objects were converted by the DispatcherServlet to JSON.

Saturday, 7 September 2013

Injecting Dependencies in a CXF Endpoint

We have seen how easy it is to create CXF endpoints. In the previous post on WSDL first web services we had defined server endpoints as:
<jaxws:endpoint id="randomWs"
   implementor="com.ws.service.samplews_ns.SampleServiceOperationsPortTypeImpl"
   address="randomService" />
The "randomWs" endpoint is a CXF endpoint capable of processing SOAP requests, It is also a spring managed bean.

Tuesday, 3 September 2013

Exception Handling in Spring REST calls

I earlier did a post on error handling in Spring web applications. It was related to generating views for errors. But in a REST application we would prefer to return error codes or error JSON message. While the earlier style can be still used here to write out an appropriate JSON error response, Spring MVC provides other mechanisms to handle errors.