rapvamshi-blog
rapvamshi-blog
jumblecode
30 posts
Don't wanna be here? Send us removal request.
rapvamshi-blog · 7 years ago
Text
Lifecycle callbacks
The spring framework provided 2 types of Lifecycle callbacks and those are:
initialization callback: Spring Container will invokes the methods of initialization callbacks after initialization of bean and its dependencies.
Destruction callback: Spring Container will invokes the methods of destruction callbacks before container destroys.
Internally, the Spring Framework uses BeanPostProcessor imple…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Custom Scopes
Spring framework provided facility to define custom scopes but you cannot redefine existing scopes (singleton, prototype).
You can define custom scope and integrate into spring container in two ways.
Through implementing the scope interface and overriding the unimplemented methods.
Through XML configuration file.
custom scope implementation through programmatic:
To integrate your custom scope(s)…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Method Injection
Suppose singleton bean A needs to use non-singleton (prototype) bean B, perhaps on each method invocation on A. The container only creates the singleton bean A once, and thus only gets one opportunity to set the properties. The container cannot provide bean A with a new instance of bean B every time one is needed.
SingletonBean class has dependency PrototypeBean class and it having scope as…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Lazy-initialized Beans
By default, ApplicationContext implementations eagerly create and configure all singleton beans as part of the initialization process. Generally, this pre-instantiation is desirable, because errors in the configuration or surrounding environment are discovered immediately, as opposed to hours or even days later.
The below snippet of code will eagerly create and configure all singleton beans as…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Site Settings ‹ Jumble Code — WordPress.com
Site Settings ‹ Jumble Code — WordPress.com
via Site Settings ‹ Jumble Code — WordPress.com
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Autowiring
The Spring container can autowire relationships between collaborating beans. You can allow Spring to resolve collaborators (other beans) automatically for your bean by inspecting the contents of the ApplicationContext. Autowiring has the following advantages:
Autowiring can significantly reduce the need to specify properties or constructor arguments.
Autowiring can update a configuration as…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Lazy Initialized Beans
By default, ApplicationContext implementations eagerly create and configure all singleton beans as part of the initialization process. Generally, this pre-instantiation is desirable, because errors in the configuration or surrounding environment are discovered immediately, as opposed to hours or even days later. When this behavior is not desirable, you can prevent pre-instantiation of a…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
XML Shortcut with p and c namespaces
XML Shortcut with p and c namespaces
XML shortcut with p-namespace:
The p-namespace enables you to use the bean element’s and attributes, instead of nested <property/> elements, to describe your property values and/or collaborating beans.
<?xml version=“1.0” encoding=“UTF-8”?>
<beans xmlns=“http://www.springframework.org/schema/beans&#8221;
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance&#8221;
xmlns:p=“http://www.springfram…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Using depends on
If a bean is a dependency of another that usually means that one bean is set as a property of another. Typically you accomplish this with the <ref/> element in XML-based configuration metadata. However, sometimes dependencies between beans are less direct; for example, a static initializer in a class needs to be triggered, such as database driver registration. The depends-on attribute can…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Bean Scopes
Spring framework provided two types of scopes in core. They are:
singleton
prototype
Singleton:
Only one shared instance of a singleton bean is managed, and all requests for beans with an id or ids matching that bean definition result in that one specific bean instance being returned by the Spring container.
To put it another way, when you define a bean definition and it is scoped as a…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Null and Empty Strings
Null and Empty Strings
Spring framework treats empty arguments for properties as empty strings.
<bean class=”CustomerBean”>
<property name=”cust_Name” value=””/>
</bean>
  <null/> element will gives null to a property and it is other way to provide null values to a property like below,
<bean class=”CustomerBean”>
<property name=”cust_Name”>
<null/>   
</property>
</bean>
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Constructor Injection With Collection
Constructor Injection With Collection
Spring framework provides support of collection framework. The collection in the sense, list, set, map and properties interfaces are included. In this post, we will see how this collection framework will be handled in spring through constructor injection.
Constructor Injection With List Collection:
List allows to add duplicate elements and ‘null’ elements. To set values to list collection then…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Injecting Inner Bean
An inner bean definition does not require a defined id or name; if specified, the container does not use such a value as an identifier. The container also ignores the scope flag on creation: Inner beans are always anonymous and they are always created with the outer bean. It is not possible to inject inner beans into collaborating beans other than into the enclosing bean or to access them…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Setter Injection with Collection
Setter Injection with Collection
Spring framework provides support of collection framework. The collection in the sense, list, set, map and properties interfaces are included. In this post, we will see how this collection framework will be handled in spring.
Setter Injection with List collection:
List allows to add duplicate elements and ‘null’ elements. To set values to list collection then element and its sub element are…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Setter Injection with Collection
Setter Injection with Collection
Spring framework provides support of collection framework. The collection in the sense, list, set, map and properties interfaces are included. In this post, we will see how this collection framework will be handled in spring.
Setter Injection with List collection:
List allows to add duplicate elements and ‘null’ elements. To set values to list collection then element and its sub element are…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
Constructor Injection
If the dependencies are injected by calling constructor of an object then it is called constructor injection.
Example:
Below class is POJO class i.e., StudentBean Class having private member variables and parameterized constructor.
package com.spring.constructor;
//Bean class
public class StudentBean {
public StudentBean(String stdName, int rollNum, Marks marks) {
this.stdName = stdName;
this.…
View On WordPress
0 notes
rapvamshi-blog · 7 years ago
Text
POJO
Plain Old Java Object (POJO) is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to
Extend prespecified classes
Implement prespecified interface
Contain prespecified annotations
Example: package com.spring.setter;
//Bean class
public class StudentBean {
//variables
private String stdName;
private int rollNum;
p…
View On WordPress
0 notes