Spring multiple configuration classes: Loading beans, components, repositories, configurations from other packages

In the beginning, I had a hundred problems creating beans, and spent hours to understand how spring works. I produce a lot of modules and libraries and separate everything by features. So, my applications don’t have a simple model-view-controller folder-set as I have hundreds or even thousands of classes in enterprise solutions. And, I was facing issues with setting up my libraries which were not in the application package in spring. By application package I mean where the Spring Application class resides in and all the sub-packages.

So, what happens when packages are outside? – the beans are not created, the spring annotations do not work! The solution is pretty easy but hard to find unless you are already familiar with “spring keywords“. But, the only way to get familiar with spring terminology is to become a master of it first! Anyway, so my goal here is to write tutorials which would be easy to find with common keywords like “my beans are not working in spring”.

Read More »


Springboot and MongoDB: Creating indices on inherited properties or fields.

I started writing my first spring and the first springboot application today. The project requires mongodb and mysql as databases. My application’s domain objects are highly hierarchical and we need to make different kinds of search engines for many child classes. So, there needs to be some violations from common patterns like “field shadowing”. Though it’s only for the purpose of data and search layer, it doesn’t affect the object model of the application. So, I needed to change field behavior in subclasses which are different entities or collections in Mongo store. Basically I needed to put a annotation on subclass to enable an index on a field.

Read More »

Spring bean scopes

I just learned it!

code dweller

When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, To force Spring to produce a new bean instance each time one is needed, you should declare the bean’s scope attribute to be prototype. Similar way if you want Spring to return the same bean instance each time one is needed, you should declare the bean’s scope attribute to be singleton.

The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.

Scope Description
singleton This scopes the bean definition to a single instance per Spring IoC container (default).
prototype This scopes a single bean definition to have any number of object instances.
request This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
session This scopes a bean definition to an…

View original post 33 more words

Spring Collection Injection: How does it actually work

I am learning Java Spring Framework out of personal interest. I am trying to understand how it works. Today I was learning dependency injection in Spring. I started with injecting java collections through xml beans. As you already know, if you want to set a property of primitive type, you need to put exactly the same property name in bean xml definition. I started with that for injecting a List collection named addressList.

Read More »