Posts

Showing posts from October, 2012

Spring 3 part 3: Standard wiring

This is the 3rd part of the Spring 3 Series . In the part 2 of this series explained the Spring way of wiring. The part 2 examples are continued in this blog.mThis part is dedicated to standard wiring that is proposed by the Java Community Process. Spring 3 implements the JSR-330 that is @Inject annotation. The @Inject is lot common to the @Autowire but no “required” attribute. import javax.inject.Inject; import javax.inject.Named; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Parent { @Inject @Named("grandChild") private Child child; The Parent class’s child property is annotated with @Inject and @Named. Here @Named is similar to @Qualifier, for instance grandChild is declared as a Spring bean in the spring-config.xml file which is referenced in the @Named annotation. It is also possible to create custom qualifier as an alternative way. Here the custom qual

Spring 3 part 2: Auto wiring

Image
This is the 2nd part of the Spring 3 Series . In the first part of this series, I discussed how to create maven Spring 3 project.The objective of the second part is to discuss the Spring 3 auto-wiring. Fist look into the Spring 2.5 auto-wiring which is based on the byName, byType, constructor and autodetect. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <!-- context:annotation-config/--> <bean id="parent" class="au.com.blogspot.ojitha.spring3tut1.Pa

Spring 3 part 1: Getting started with maven 3

Image
This is the 1st part of the Spring 3 Series . I know most of you know how to create spring project from maven. This blog I write as a part of the completion of series of my blogs on Spring 3. The my way of creating spring project is, first creating a simple java project and enhanced it up to the Spring project as I want. As shown above figure, the maven command will create first-tut project underneath the maven-projects directory. Now you are ready to import existing maven project to STS. I you are typical Eclipse user, then you can use mvn eclipse:eclipse before import. And you need to create global variable M2_REPO in the Eclipse. In STS there is m2Eclipse integration, therefore you can directly import as shown in the following figure Via STS, you can add spring dependencies as shown in the following You can find the following dependencies just typing “org.spring”. This will update the pom.xml file as follows. < project xmlns = " http://maven.apache.org/POM/4.0.