Share on Google+Share on Google+

Setter injection in Spring
2 Answer(s)      5 years and 6 months ago
Posted in : Spring

What is Setter injection in Spring ?


View Answers

October 19, 2011 at 11:37 AM

The Spring IoC container supports setter injection, which is the preferred method of dependency injection in Spring. Setter injection uses the set* methods in a class file to garner property names that are configurable in the spring XML config.

From a configuration standpoint, setter injection is easier to read because the property name being set is assigned as an attribute to the bean, along with the value being injected.

For more information,visit the following link:

Spring Setter Injection

October 19, 2011 at 11:48 AM

Hi In Spring by using setter injection we set the value of instance variable of an object from the xml file this gives the flexibility to change the value without compiling the class

For this you have to configure the your bean class into the XML bean file suppose you have a student bean class then you can configure this class in bean xml file as

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" 0
    xmlns:xsi="" 0
    <bean id="student" class="net.roseindia.StudentBean">
        <property name="roll" value="1" />
        <property name="name" value="Vinay Kumar" />
        <property name="course" value="MAC" />

In the bean class there are there instance variable roll, name and course...

then call the xml file in your application as

ApplicationContext context = new ClassPathXmlApplicationContext(
        StudentBean bean = (StudentBean) context.getBean("student");

Related Tutorials/Questions & Answers:
Setter injection in Spring
Setter injection in Spring  What is Setter injection in Spring ?   The Spring IoC container supports setter injection, which is the preferred method of dependency injection in Spring. Setter injection uses the set
Spring Setter Injection
Basic Setter Injection Here in this example you will see another different type of injection known as setter injection which is the preferred method dependency injection in Spring. The convention of writing the setter method
spring injection
spring injection  what is difference between constructor and setter injection and which is better
Spring Setter Injection
Spring Setter Injection The In Spring framework Setter Injection is used to inject the value into the instance variable from the xml file without hard coding.../beans"> <
a quesiton on spring injection
a quesiton on spring injection  i have copied your spring injection example/ its not working in my pc i am using eclipse4 th version. XmlBeanFactory is depricated and classnot found exception please help me i am new
Spring Injection Example
Spring Injection Example       XML Bean-Injection, The given example below gives the brief...; Output of the Spring Injection Example program Nov 25, 2008 1:03
What are the types of Dependency Injection Spring supports
What are the types of Dependency Injection Spring supports  Hi, What are the types of Dependency Injection Spring supports
The ref in Spring, Reference Injection
Reference Injection In the reference injection one bean definition is injected to another. For reference injection you use the constructor-arg or property...;
Constructor Based Dependency Injection in Spring
Constructor-based dependency injection In the constructor-based dependency injection one bean definition is injected to another. For this  you use...;bean.display("hello spring");   
Spring Injection Example
Spring Injection Example       XML Bean-Injection, The given example below gives the brief...,;  } } Output of the Spring Injection Example
Spring Constructor Injection Example
Spring Constructor Injection Example In Spring Framework the constructor injection is also a type of Dependency injection (like Setter Injection).  An Example of Constructor Injection is given below package
Benefit of Spring Injection over Hibernate / JDBC w/Oracle
Benefit of Spring Injection over Hibernate / JDBC w/Oracle  Im new to Spring and am still trying to understand the advantages over using jdbc (I... the tutorial titled "Spring 2.5 - Spring Injection Example" (http
Spring Injection Example
Spring Injection Example       XML Bean-Injection, The given example below gives...);   } } Output of the Spring Injection Example
Spring Constructor Injection
Basic Constructor Injection In this example you will see how the Spring beans... injection. package .../schema/beans/spring-beans-3.0.xsd">   <bean id="basic
SQL injection
SQL injection  hii, What's an SQL injection?   HII, SQL Injection is when form data contains an SQL escape sequence and injects a new SQL query to be run
java - Spring
is setter injection? how to write configaration file with  if we want to execute spring program what are the basic files we need? how to write the spring program?i want small example with code. what
spring   hi how can we make spring bean as prototype how can we load applicationcontext in spring what is dependency injection
What's an SQL injection?
What's an SQL injection?  What's an SQL injection
MySQL Injection
Mysql Injection       In this section we will learn what is MySQL Injection and how.... This tutorial explains discussing the issue which is known as SQL Injection
hibernate pojo setter method problem
hibernate pojo setter method problem  how to pass a date type variable to a setter method in hibernate pojo class? //this is my pojo class import java.util.*; public class Employee { private String empname; private int
Spring  I understand spring as dependency injection. It can avoid... injection can not be done without respective classes. Du to this condition, i am... are created. By the same way i want to know how spring injected property
Spring IoC, Spring 3 IoC Container Tutorial and example code.
of the Spring Framework provides Dependency Injection and Inversion of Control (IOC... the constuctor.   Setter Injection The setter injection is done through the setters (setter method).   Interface Injection
Why to use Spring Framework?
. There three ways of Dependency Injection in Spring Framework: Setter... of the applications. Check the example of Spring Setter Injection... of the Spring framework and it works on the Dependency Injection and Inversion
Why setter and getter methods - Development process
Why setter and getter methods  Every field has setter and getter... and setter methods are used to retrieve and manipulate private variables in a different class. The getter methods retrieves the attribute of the same name and setter
PHP SQL Injection Example
PHP SQL Injection Example  This Example illustrates how to injection..., the injection attack has actually made our query behave differently than we intended...; echo "Injection: " . $query1 . "<
spring  Access JSP files in Spring
spring  javascript browse image in spring progrme
spring  how to upgrade from struts2 to spring
spring  sir how to access multiple jsp's in spring
spring   i am a beginner in java.. but i have to learn spring framework.. i know the core java concepts with some J2EE knowledge..can i learn spring without knowing anything about struts
spring  sir can you explain me the flow of sample example by using spring? thanks
Java Spring Hibernate Struts Training spring inteview question You Spring Project is not running java lang incompatibleclasschangeerror quartz spring - Error resolved exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined The import javax.validation cannot be resolved java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence Solving java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean issue What is the maven dependency for spring batch? Hibernate Session Attribute java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource Testing spring with junit and mock testing in Spring MVC, i would like to download my Mysql database table in pdf,msword,excel formats. java.lang.NoClassDefFoundError: org/hibernate/engine/FilterDefinition error package org.springframework.scheduling.quartz does not exist jquery dependency dropdown box in spring hibernate my sql Server side validation on dynamically generated fields from more than one table on spring framework. What are the new features of Spring 4.1? Append Arguments to the URL quartz schedular in spring mvc Where to download spring framework zip file? Integrating spring 4 with hibernate 4 Learn spring Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations Spring 4 features I need Spring 2.5 example. Please point me towards a good Spring transactional tutorial Could anyone point me towards some good Spring tutorials, Please? What is Spring framework? Spring and hibernate based Online Shopping project with source code How to populate collection like map with annotation in mybatis? Spring Abstraction with Redis Spring framework How to insert and retreive an image in mysql database using spring mvc framework??? CRUD operations in spring mvc 2.5 meenakshi Meenakshi how many scenarios is having to developing web based application by using spring mvc. getting voucherPin parent and child dropdown Spring 3 Spring 3 MVC Login Form Example with Database MySql What is Spring Integration? How to configure Spring using Annotation What is Spring IOC Container ? What is difference between singleton and prototype bean? What are the differences between EJB and Spring What is Spring's JdbcTemplate ?


Advertisement null