In this session I have described the different types of dependency injections and their usages.
Reference Link : http://en.wikipedia.org/wiki/Dependency_injection
This session describes the overview on different types of spring containers. Here we can also find simple examples showing the demo to instantiate the containers.
Spring IOC advantages and developing spring application sample Sunil kumar Mohanty
This document provides an over view of spring IOC and it's advantages. It also gives basic idea on the spring core container. At the last it describes how develop a simple spring application
This is a basic tutorial on Spring core.
Best viewed when animations and transitions are supported, e.g., view in MS Powerpoint. So, please try to view it with animation else the main purpose of this presentation will be defeated.
This session describes the overview on different types of spring containers. Here we can also find simple examples showing the demo to instantiate the containers.
Spring IOC advantages and developing spring application sample Sunil kumar Mohanty
This document provides an over view of spring IOC and it's advantages. It also gives basic idea on the spring core container. At the last it describes how develop a simple spring application
This is a basic tutorial on Spring core.
Best viewed when animations and transitions are supported, e.g., view in MS Powerpoint. So, please try to view it with animation else the main purpose of this presentation will be defeated.
This file tells about what is DAO and JDBC in the Spring framework, and the components present in Spring Framework.
This File is having Several Examples for Spring JDBC.
Starting with Spring MVC 2.5, Annotation-Based Controllers became the preferred model for development (the Interface-based Controller hierarchy will be deprecated in Spring 3). This session will teach developers familiar with the old model how to use the new Annotation-based Controllers. This will also provide the basis for writing JSR 286 portlets using Spring 3.
Sample code available here:
http://www.ja-sig.org/wiki/x/vYS8AQ
Full screencast available here:
http://vimeo.com/10020881
This file tells about what is DAO and JDBC in the Spring framework, and the components present in Spring Framework.
This File is having Several Examples for Spring JDBC.
Starting with Spring MVC 2.5, Annotation-Based Controllers became the preferred model for development (the Interface-based Controller hierarchy will be deprecated in Spring 3). This session will teach developers familiar with the old model how to use the new Annotation-based Controllers. This will also provide the basis for writing JSR 286 portlets using Spring 3.
Sample code available here:
http://www.ja-sig.org/wiki/x/vYS8AQ
Full screencast available here:
http://vimeo.com/10020881
A Brief presentation on Containerisationsubhash_ae
A brief presentation on Containerisation , the advent of Containerisation , use of marine containers to carry cargo across the oceans , description and types of marine containers , technical details of the marine containers etc. etc.
Introduction to the Spring Framework:
Generar description
IoC container
Dependency Injection
Beans scope and lifecycle
Autowiring
XML and annotation based configuration
Additional features
This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2016.
http://www.ivanomalavolta.com
Mahika Tutorials sharing Java Spring Framework Tutorials. You can visit our YouTube Page for Video Session also : https://www.youtube.com/c/mahikatutorials
Introduction
Framework Modules
Spring Dependencies
Dependency Injection
The IoC Container
Spring IoC Container and Beans
XML-based Configuration Metadata
XML-based Beans
Instantiation of Beans
Dependency Injection
Bean Scopes
Depends On & Lazy-initialized Beans
Customizing the Nature of a Bean
Using PropertyPlaceholderConfigurer
https://notebookbft.wordpress.com/
This is a step by step slides to study JSP, all the concepts which are required for a JSP are present in this ppt. The whole JSP is divided into SESSIONS.
Similar to Types of Dependency Injection in Spring (20)
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
I have heard many times that architecture is not important for the front-end. Also, many times I have seen how developers implement features on the front-end just following the standard rules for a framework and think that this is enough to successfully launch the project, and then the project fails. How to prevent this and what approach to choose? I have launched dozens of complex projects and during the talk we will analyze which approaches have worked for me and which have not.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Let's dive deeper into the world of ODC! Ricardo Alves (OutSystems) will join us to tell all about the new Data Fabric. After that, Sezen de Bruijn (OutSystems) will get into the details on how to best design a sturdy architecture within ODC.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Types of Dependency Injection in Spring
1. Different types of Dependency Injections and their Usages
In this session I am going to focus on the various types of dependency
injections in spring core. In the last session we had a brief overview on
dependency injection and spring container . We have already discussed on the
importance of dependency into object for various benefits. Now let us focus on
the different types of dependency injection processes and there importance. The
dependency injection option can be classified into two types.
Dependency Injection Types:
1. Constructor Injection
2.SetterMethod Injection
The constructor method of dependency injection is the process of injecting the
dependencies of an object through it’s constructor arguments. In this mechanism
the dependencies are pushed to the object through the constructor arguments at the
time of instantiating it. The following code snippet shows the sample class that
allows the injection of it’s dependencies as constructor arguments.
StudentDAODBImpl.java
package com.demo.spring;
import java.sql.*;
import javax.sql.*;
public class StudentDAODBImpl implements StudentDAO {
private DataSource dataSource;
public StudentDAODBImpl(DataSource ds) {
dataSource = ds;
}
public double getName(int rollNo) {
//Use the datasource to handle the request
}
// Continue with the rest of the code
}
2. In the above code snippet we can observe that StudentDAOImpl is dependent on
the DataSource to complete the request that is to connect to the database it
requires a javax.sql.DataSource object which is getting injected as a constructor
argument here. Now I am going to explain how to configure the been definition
describing the usages of constructor with arguments.
Spring beans XML configuration tag to configure constructor arguments:
The bean definition can described to use a constructor with zero or more
arguments to instantiate the bean. the <constructor-arg> element describes one
argument of the constructor , which means that to specify a constructor with more
than one element we need to use <constructor-arg> element multiple times. The
argument specified in the bean definition correspond to either a specific index of t
he constructor argument list or supposed to be matched generally by types.
The <constructor-arg> element supports four attributes as follows.
1. index : This attribute takes the exact index in the constructor argument list.
This can be used to avoid ambiguities like in the case of two arguments
being of the same types.
2. type : This attribute takes the type of this constructor argument.
3. value : These are sub tag of the <constructor-arg> tag to represent values of the
field.
4. ref : This tag is used to refer to another bean to use it as a constructor
argument.
The <constructor-arg> element supports variety of types of as argument. Also the
<constructor -arg> element supports various sub tags each of which allows us to
describe different types of values. The various types of sub tags are as follows.
1. Element : value
Syntax : <value>content</value>
Description : The value element describes the content is simple string
representation which will be converted in to the argument type
using the java bean PropertyEditors.
Example : <constructor-arg type=“int”>
<value>1000</value>
3. </constructor-arg>
The “1000” content described by the <value> tag is converted into int type
2. Element : null
Syntax : <constructor-arg type=“String”> <null/></constructor-arg>
or
<constructor-arg type=“String”>
<value><null/></value>
</constructor-arg>
Description : This is required to represent the null value, since the empty <value>
element will be resolved into an empty string.
3. Element : ref
Syntax : <constructor-arg type=“String”>
<ref local=“ds”/>
</constructor-arg>
Description : This tag references to another bean in this factory or an external
factory. Here the external factory is the parent factory or the
included factory. This sub tag supports three attributes: local,
parent, bean
local : It is used to refer to another bean with its Id in the same xml
file.
parent : It is used to refer to another bean with it’s id in the parent
or included XML configuration file.
bean : it is use to refer to another bean with it’s name in the same
xml file.
4. Element : list
Description : it describes a java.util.List type.
5. Element : set
Description : it describes java.util.Set type
6. Element : map
4. Syntax :
<constructor-arg type=“String”>
<map>
<entry>
<key>
<value>name</value>
</key>
<value>sunil</value>
</entry>
<entry>
<key>
<value>address</value>
</key>
<value>TKL</value>
</entry>
</map>
</constructor-arg>
Description: It describes the java.util.Map type. A map can contains zero or
more entry elements each of which describes one map entry. The
map entry describes one key and value.
7. Element : prop
Syntax:
<constructor-arg type=“java.util.Properties”>
<props>
<prop key=“name”>SNL</prop>
<prop key=“address”>TKL</prop>
</prop>
</constructor-arg>
Description : The <props> element describes a java.util.Properties type. It can
contain zero or more <prop> elements where each <prop>
element describes one entry. The property entry describes one ket
and value.
8. Element : bean
Description : The bean element describes a bean
In the above discussion we learnt about the <constructor-srg> elementa and it’s
sub elements. The following code snippet shows the bean definition for the
StudentDAODBImpl class in the spring beans XML configuration file. It
instructs the spring IOC Core container to inject the DataStructure object into
StudentDAODBImpl while creating an object.
Code Snippet :
5. <beans>
<bean id=“empdao”
Class=“com.demo.spring.dao.StudentDAODBImpl”>
<constructor-arg>
<ref local=“ds”/>
</constructor-arg>
</bean>
</beans>
The above code snippet indicates the injection of bean with [id=“ds”] into
StudentDAODBImpl object as an constructor argument .
In the below code snippet I am going to discuss on Dependency injection during
constructor overloading.
Constructor OverLoading and Ambiguity resolution:
In the below example there exists a class with two over loaded constructors. We
are going to use the constructor injection in more efficient manner to over come
the argument ambiguity. We will use the index or type attribute of the
<constructor-arg> as per the necessity to resolute the conflict.
Code Snippet:
package com.demo.spring;
public class DemoClass {
public DemoClass(int id, String name) {
// Some Code
}
public DemoClass(String name, int id) {
// Some Code
}
}
syntax 1:
<!—bean definition in xml file >
<!— Bean definition using the constructor int and string
respectively >
<bean id=“demo” class=“com.demo.spring.DemoClass”>
<constructor-arg>
<value>10</value>
</constructor-arg>
6. <constructor-arg>
<value>abc</value>
</constructor-arg>
</bean>
syntax 2:
<!—This bean definition uses constructor with argument string
and int i.e here the the value 10 will be used as a string and
the value 100 will be used as integer to initialize the
constructor>
<bean id=“demo” class=“com.demo.spring.DemoClass”>
<constructor-arg type=“java.lang.String”>
<value>10</value>
</constructor-arg>
<constructor-arg type=“java.lang.Integer”>
<value>100</value>
</constructor-arg>
</bean>
syntax 3:
<!—This bean is using the constructor with argument int and
String respectively. Here the constructor is getting recognized
by considering the the index as well as the type of the
constructor argument >
<bean id=“demo” class=“com.demo.spring.DemoClass”>
<constructor-arg index=“1” type=“java.lang.String”>
<value>8082</value>
</constructor-arg>
<constructor-arg index=“0”>
<value>82</value>
</constructor-arg>
</bean>
The above syntaxes describes the various types of configuration formats with
<constructor-arg> element to get the required constructor. The arguments starting
index is always 0 and it is recommended to use the index if more number of
arguments are going to be get configured . It is wise to use Constructor injection
when there exists minimal number of dependencies.
Setter Injection :
Here dependencies of an objects are used to get injected using the setter method. It
is efficient to use setter injection when there exists more number of dependencies.
The following sample code will describe a demo class which allows its
dependencies to be get injected using the setter method of injection.
7. import com.demo.spring.dao.StudentDAO;
public class StudentServiceImpl implements StudentService {
private StudentDAO studentDAO;
public void setStudentDAO(StudentDAO studentDAO) {
this.studentDAO = studentDAO;
}
// Some Code
}
In the above example we can see that the StudentServiceImpl is dependent on
StudentDAO. The StudentDAO object is required to perform the persistence
operation and it is getting injected using the setter method to the
StudentServiceImpl class. The below discussion describes how to configure the
bean definition and also describes how to use setter method injection.
Use of property Element :
The bean definition can use zero or more properties to inject before making the
bean object available to the application. The property element is used to set the
arguments for the setter method. The property element support three arguments as
described below.
name : This attribute takes the name of java bean property. It uses the Java bean
naming convention like a name “dao” will correspond to setDao as a
setter method.
value : It corresponds to the child element “value” as described in the under the
constructor injection.
ref : it refers to a child element “ref bean=”
The child elements for the <property> element are same as of the <constructor-arg>
described in previously.
example:
<bean id=“demo” class=“com.demo.spring.StudentServiceImpl”>
<property name=“studentDAO”>
<ref local=“studentdao”>
</property>
8. </bean>
The above code indicates that to set a reference of a spring bean object named
studentdao to the property ‘studentDAO’ of StudentServiceImpl .
Importance of using the property namespace:
Spring 2.0 provides the support to use our own tag with our own name name
space as per our requirement an d as per the convenience. This property name
space provides a way to simplify the configuration document. It eliminates the use
of <property> tag for specifying the the property injection.
For the use of property namespace we need to import the following name space
xmlns:p=“http://www.springframework.org/schema/p”
Importing this name space in bean tag allows us to use the property namespace
with prefix ‘p’ throughout the definition. We use the property name as an attribute
name with prefix ‘p:’ to specify the value for the property.
<bean id: ” demoBean ” class=“com.demo.spring.DemoBean”
p:message=“HelloWorld” />
This specifies to set a spring value HelloWorld to the property ‘message’ of
DemoBean. If it is required to refer to another bean as a value for the property, we
need to append ‘-ref’ to the property name. The below code snippet demonstrates
it.
<bean id=“demoBean1” class=“com.demo.spring.DemoBean1”/>
<bean id=“demoBean2” class=“com.spring.DemoBean2”
p:demoBean-ref=“demoBean1/”>
This code snippet specifies to set reference of a spring bean object . named
“demoBean1” to the property ‘myBean’ of myBean2 . It invokes the
setDemoBean(DemoBean1 arg).
Dependency Injection Example :
In the preceding discussion we have brief idea on the dependency injection. Now
we are going to design an example to demonstrate the constructor and setter
method injection.
StudentServices.java shows a simple business object interface that represents the
9. services related to student.
package com.demo.spring.service;
/**
* interface for the business object
*
* @author sunilm
*
*/
public interface StudentService {
public boolean insertStudentInfo(int id, String name);
}
StudentServiceImp.java is the implementation of the StudentService.java
StudentServiceImp.java
package com.demo.spring.service;
import com.demo.spring.dao.StudentDAO;
/**
* Implementation of the StudentService Interface
*
* @author sunilm
*
*/
public class StudentServiceImpl implements StudentService{
private StudentDAO studentDAO ;
/**
* set StudentDAO
*
* @param studentDAO
*/
public void setStudentDAO(StudentDAO studentDAO) {
this.studentDAO = studentDAO;
}
10. /**
* insert the student name to the database and check the correctness
by retrieving it
* corresponding to the same student id
* @param id student id
* @param name name of the student
* @return insertationStatus status of execution
*/
public boolean insertStudentInfo(int id, String name) {
boolean insertationStatus = false;
studentDAO.setName(id, name);
String studentName = studentDAO.getName(id);
if(name.equals(studentName)) {
insertationStatus = true;
}
return insertationStatus;
}
/**
* Extracts the name of the student
* @param id students unique id
* @return name of the student
*/
public String extractStudentInfo(int id) {
return studentDAO.getName(id);
}
}
StudentDAO.java interface with a minimum set of methods , which will be
enhanced further as per the requirement.
package com.demo.spring.dao;
/**
* Interface for the business Object
*
11. * @author sunilm
*
*/
public interface StudentDAO {
String getName(int id);
void setName(int id, String name);
}
StudentDAODBImpl.java is the enhancement of the StudentDAO.java interface
StudentDAODBImpl.java
package com.demo.spring.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
/**
* Implementation of the Studentservice[BusinessObjectinterface]
* @author sunilm
*
*/
public class StudentDAODBImpl implements StudentDAO {
private DataSource dataSource;
/**
* Constructor to initialize the datasource
*
* @param dataSource
*/
public StudentDAODBImpl(DataSource dataSource) {
this.dataSource=dataSource;
}
12. /**
* Retrieve the name of the student with respect to the provided id from
the database
* @param id id of the student
* @return name name of the student
*
*/
public String getName(int id) {
Connection con = null;
String studentName = "";
try {
con = dataSource.getConnection();
PreparedStatement ps = con.prepareStatement("select name
from student where id=?");
ps.setInt(1, id);
ResultSet rs=ps.executeQuery();
if (rs.next()) {
studentName = rs.getString(1);
} else {
throw new RuntimeException("Student not found");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e) {
// log the error
e.printStackTrace();
}
} return studentName;
}
/**
* Keep the information of the student in the database
* @param id unique id for the student
* @param name name of the student
13. */
public void setName(int id, String name) {
Connection con = null;
try {
con = dataSource.getConnection();
PreparedStatement ps = con.prepareStatement("update student
set name=? where id=?");
ps.setString(1, "piixbuf");
ps.setInt(2, 101);
int count = ps.executeUpdate();
if(count == 1 || count == Statement.SUCCESS_NO_INFO) {
return;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try{
con.close();
} catch(SQLException e){
e.printStackTrace();
}
}
}
}
Now we have to configure these beans into spring beans XML configuration file.
The following demobeans.xml shows the spring bean XML configuration file
with respective datasource .
Demobeans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id = "studentDAO" class = "com.spring.demo.dao.StudentDAODBImpl" >
14. <constructor-arg>
<ref bean="ds"/>
</constructor-arg>
</bean>
<bean id = "ds" class= "org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@localhost:1521:orcl</value>
</property>
<property name="username">
<value>scott</value>
</property>
<property name="password">
<value>tiger</value>
</property>
</bean>
<bean id="studentService" class="com.demo.spring.StudentServiceImpl">
<property name="studentDAO">
<ref bean="studentDAO"/>
</property>
</bean>
</beans>
In the above example we have completed the business implementation and spring
XML configuration. Now we have to write the test class to test the StudentService
class. It will insert a students name into the data base against a specific ID. After
that in the next step it will retrieve the same student name using that specific ID.
Now it compares the inserted data with the retrieved the value to check if the
execution took place successfully or not. In the above example both setter and
constructor injection got used.
StudentServiceTest.java
package com.demo.spring.test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import com.demo.spring.service.StudentService;
/**
15. * Test the StudentService class execution
* @author sunilm
*
*/
public class StudentServiceTest {
public static void main(String[] args) {
String studentName = "pixbuf";
BeanFactory beans = new XmlBeanFactory(new
FileSystemResource("demobeans.xml"));
StudentService stdService =
(StudentService)beans.getBean("studentService");
stdService.insertStudentInfo(101, studentName);
String nameFromDataBase =
stdService.extractStudentInfo(101);
if (studentName.equalsIgnoreCase(nameFromDataBase)) {
System.out.println("Excution Success");
}
}
}
Hope this discussion helps in understanding the different
types of dependency injections as well as there uses. Thank you all