Some times there might arise situations where you want to create a number of Spring Beans, but you don’t know how many beans are there at coding time.
Usually, you create a Spring bean as follows:
But what if you want to create 50 such beans which differ only in the argument supplied to the constructor? Or a similar case arise where the number of beans to be created cannot be determined at coding time?
In such cases, we can create the bean definitions and add the beans to Spring container at runtime using BeanFactoryPostProcessor.
Implement BeanFactoryPostProcessor in either a @Configuration file or a @Component bean(make sure this bean gets scanned and created).
If there are more than one constructor arguments, the call can be chained as follows:
All this works fine when you have to create a bean using constructor. But :( I haven’t figured out how to do this when we use a chain of factory methods to create a bean as follows:
Happy Coding! :)
There is a very good documentation in Jersey website: https://jersey.java.net/documentation/latest/jaxrs-resources.html and https://jersey.java.net/documentation/latest/filters-and-interceptors.html
Here is a small flowchart that I made showing how the JAX-RS flow works:
Happy coding :)
About two months back, me and a friend of mine went for trekking at Skandagiri Hills. Its about 75km from Bangalore near to Nandi Hills.
We started on my Yamaha Fz at about 2:30AM and reached there by 4.30AM. The place has got a few locals who are waiting there to get hold of your money in the form of parking and acting as guide! We parked (gave the guy Rs20/30 just to make sure he don’t destroy my bike) and dismissed the idea of having a guide. The trek started and we reached the top by 5.15 in the morning. The view was awesome!
Here is a map of the area and route to be taken. It’ll save you the cost of having a guide and give you a sense of adventure as you are finding way through pitch dark (if there is no moonlight ;)). Remember to take a good torchlight and a jacket. It’ll be very cold at the top. Its an easy trek. Once you find the muddy lane you can easily reach the top – you don’t require any guide! There is a small catch though – there is a route which you shouldn’t take – its marked in red colour. This red route is considerably wider and it reaches a dead-end! But what’s the fun if there is no thrill in finding the right way!
We started back by 10 in the morning. On the way back we stopped at a small Fort near Nandi hills – Fort Devanahalli. Took some pictures and then headed back to Bengaluru!
Now I should watch the remaining of the series.
Happy Coding and Keep smiling :)
And now, the previous blog post made me thinking… Why didn’t I learn .NET, C#, DirectX or other Microsoft technologies?
Maybe, because I am a fan of opensource platforms (excuse, I know there is Mono), languages and tools.
And maybe, there is a little Leftist hidden in me. (I would like to call myself opportunistic Leftist though :), and by the way I believe most of the Keralites have a soft corner for Communist beliefs – that’s why Kerala is one of the few states where Communists are still strong). And the words opensource and free software bring the thoughts of Freedom, independence and revolution to the mind.
Using Microsoft technologies, means tied to Microsoft platform and tools. I guess the leftist in me doesn’t want to get tied up.
PS: I switched back to using Windows a couple of years ago though. Was a hardcore Linux fan before. If I hadn’t I would have turned into a mad FOSS fanatic! Phew.. that didn’t happen, and am glad it didn’t!
The past 6 months had been very fruitful for me. I have added many stuffs to my skill set in this small span of time. Here are some of it:
- The new Java kid – Java 8
- Spring Security
- Creating zero-xml Spring projects using Spring javaconfig and Spring Boot
- Spring AOP
- Git(had used it before, but had been using it almost daily for past 6 months)
- Spring Data Redis
- Spring Data JPA
- REST(using Spring’s REST as well as JAX-RS spec)
- Security – PKI, Encryption-Decryption, Certificates, Auth mechanisms (like BASIC and Digest) etc., How to use tools like Fiddler
- C# – Read-only knowledge :) I don’t know to write a single line of code in C#, but I can understand a fairly large C# codebase given some time. I think that’s fair amount of improvement for a guy who haven’t looked into .NET code before.
Hmm.. that’s a pretty impressive list ;)
Happy Coding! :)
Bootstrapping Dev env for Angular JS:
- Download Node.js
- Install http-server using following command: npm install http-server -g
- Run the server as follows: http-server /path/to/the root/folder/of/webapp
That’s it. You need not do any packaging to set up the dev environment (do not use this for production though, there should be better secure ways). And the best part is all the changes in the files are immediately reflected. No restart of server is required.