
KnpCode » Spring
165 FOLLOWERS
Explore our articles on spring to stay up to date on latest updates, features and more. KnpCode provides Java, Spring, Bigdata, Web development tutorials with examples.
KnpCode » Spring
1y ago
In Spring framework we provide configuration data using which Spring container can instantiate beans and inject dependencies. Autowiring in Spring means Spring container can automatically resolve collaboration among beans (bean dependencies) by inspecting the contents of the ApplicationContext.
Table of contents
Spring Autowiring Modes
Autowiring in Spring
Enabling @Autowired annotation
Using @Autowired annotation
Using @Autowired annotation on setter
Using @Autowired annotation on constructor
Using @Autowired annotation on field
Using @Autowired annotation on arbitrary methods
required attr ..read more
KnpCode » Spring
1y ago
In this post we’ll see what is circular dependency in Spring and how to resolve circular dependencies.
Circular dependency in Spring
If you mostly use constructor dependency injection, it is possible to create an unresolvable circular dependency scenario. For example; Class A requires an instance of class B through constructor injection, and class B requires an instance of class A through constructor injection. In such configuration where beans for classes A and B are to be injected into each other, the Spring IoC container can’t decide which bean should be created first and throws BeanCurrent ..read more
KnpCode » Spring
1y ago
In Spring framework it is the Spring container that is responsible for instantiating beans, setting bean properties, wiring dependencies and managing the complete bean lifecycle from its instantiation to the time bean is destroyed.
Table of contents
Spring bean lifecycle callbacks
Spring bean lifecycle callback methods
Spring bean lifecycle callback methods execution order
InitializingBean and DisposableBean callback interfaces
InitializingBean and DisposableBean interfaces example
Custom init and destroy methods in Spring bean lifecycle
@PostConstruct and @PreDestroy annotations in Spring b ..read more
KnpCode » Spring
1y ago
When you inject dependencies in Spring using value or ref attribute you can set a single primitive value or a single referenced bean. What if you want to inject a collection of values as a bean dependency in Spring, for that Spring framework provides an option to inject collections like List, Set, Map.
Table of contents
Injecting collection in Spring
Injecting List and Set in Spring example
Injecting Map and Props in Spring example
Injecting bean reference in List, Set, Map
Injecting collection in Spring
In Spring framework the <list/>, <set/>, <map/>, and <props/> ..read more
KnpCode » Spring
1y ago
In this post we’ll see how to inject null and empty string values into constructor argument or property in Spring.
Injecting empty string in Spring
In Spring if you have to set any property to the empty String value then pass (“”) as a value for that property.
For example if you have an Employee bean and you want to set its email property to the empty String value (“”).
<bean id="employeeBean" >
<property name="email" value="" />
</bean>
If injected as a constructor argument-
<bean id="employeeBean" >
<constructor-arg name="email" value="" />
</b ..read more
KnpCode » Spring
1y ago
Autowiring in Spring makes life easy for the developer as the Spring container takes up the responsibility of autowiring relationships between collaborating beans by referring the contents of the ApplicationContext. Spring autowiring brings certain advantages at the same time autowiring has certain limitations and disadvantages. In this post we’ll have a look at both.
Advantages of autowiring in Spring
By using Autowiring there is a significant reduction in the explicit configuration needed to specify properties or constructor arguments.
By using autowiring maintaining code and evolution of c ..read more