This article shows Spring Dependency Injection Annotation example + Spring Auto-wiring Annotation example. We will learn Spring Dependency Injection and Beans auto-wiring using Spring @Autowired annotation. @Autowired can be applied on a bean’s constructor, field, setter method or a config method to autowire the dependency using Spring’s dependency injection. @Autowired wires the dependency using bean…
Continue readingspring
Spring Beans Auto-wiring Example using XML Configuration
Bean wiring corresponds to providing the dependencies a bean might need to complete it’s job. In Spring, beans can be wired together in two ways : Manually and Autowiring. Manual wiring : using ref attribute in <property> or <constructor> tag In this approach, we use the ‘ref’ attribute to refer to exact bean we want…
Continue readingSpring Dependency Injection Example with Constructor and Property Setter (XML)
A primary goal of Spring is to keep components as independent as possible, which allows these components to be reused , and also provides possibility to unit test them independently. Spring Dependency Injection principal fulfill this goal via injecting the dependency one component might need to complete its job, rather that component itself finding it’s…
Continue readingSpring 4 + Hibernate 4 + MySQL+ Maven Integration example (Annotations+XML)
In this tutorial , we will integrate Spring 4 with Hibernate 4 using annotation based configuration. We will develop a simple CRUD java application, creating hibernate entities, saving data in MySQL database , performing database CRUD operations within transaction, and learn how different layers interacts with each-other in typical enterprise application, all using annotation based…
Continue readingSpring @Profile Guide
In this post we will explore Spring @Profile annotation and use it to make different set of beans or configuration available conditionally on different environments. We will also discuss corresponding XML based profile configuration for comparison. Let’s imagine you have an application which includes database-interaction. You might want to configure one dataSource (for MySQL e.g.)…
Continue readingSpring @PropertySource & @Value annotations example
In this post we will see how to read values from properties files using Spring @PropertySource & @Value annotations. We will also discuss about Spring Environment interface. We will see corresponding XML configuration as well for side-by-side comparison. Spring @PropertySource annotations is mainly used to read from properties file using Spring’s Environment interface. This annotation…
Continue readingSpring Auto-detection autowire & Component-scanning Example With Annotations
In this post we will see how Spring can auto-detect the beans configured in your application using component-scanning, wire them wherever required without even declaring as @Bean methods in @Configuration class ( or in XML terms, without declaring bean in Spring XML Configuration file). We will also see corresponding XML configuration side-by-side for comparison. We…
Continue readingSpring 4 Hello World Example
This tutorial shows Spring 4 Hello world Annotation example using Spring Annotation (aka javaConfig) configuration, explains Spring 4 basic concepts & usage. XML configuration too is provided as well for side-by-side comparison. We will be creating a Maven based project using Spring 4.0.6.RELEASE. Let’s get going. Other interesting posts you may like Spring Boot+AngularJS+Spring Data+Hibernate+MySQL…
Continue reading