Introduction to Spring Expression Language(SPEL)

I think we have enough features up to now in spring, but spring is not settling down it is updating day-by-day with packs of advanced features to let its users feel spring is simple. Now we gonna see one of those feature SPEL(spring expression language). Lets have an working example of spring project using SPEL. Robot.java has two java beans(setters) which we will need to set those values from beans.xml by using SPEL. Robot.java This will return a random text when we call the getText() method. RobotText.java To enable expression language #{write expressions here} is used. Expressions //are many types

Read more

Spring autowiring by type real time example

Upto now we have seen injecting properties into beans manually. In spring there is a feature to Autowire dependencies between beans automatically thats called Autowiring. Autowiring lets you tell spring to try to figure out itself how your beans are all connected. There are several ways of autowiring in spring we gonna start now with type. Below there is an interface LogWriter.java which is implemented by ConsoleWriter.java and Filewriter.java. Logger.java had dependency on those two classes. so, now we are going to autowire those dependencies by type. LogWriter.java ConsoleWriter.java FileWriter.java Logger.java beans.xml App.java output: Hello there Write to file: Hi

Read more

setting list and set values in spring

In this post i’m gonna show you setting List values of pojo by using Spring Framework, it takes less than a minute! FruitBasket.java beans.xml App.java Note: similarly we can use set by replacing list with set in beans.xml, but as you already know set wont allow duplicate values. If you want to set other beans as list  values just use ref tag, like below Output: krishh basket contains: apple banana orange kiwi pear orange

Read more

Spring bean Scope

Scopes are there from the birth of programming language,we call it design patterns. According to gang of4 book there are 3 types of design patterns: Creational, structural, Behavioural design patterns.In creational design pattern there are singleton and prototype pattern and etc are there which we use in certain situations. In spring to use design patterns we don’t need to write code for that we just call it.By default spring is providing those for us. If we create any bean by default its scope is a singleton, If you want to modify the default one you can specify the scope type

Read more

Spring Dependency Injection

DI(Dependency injection) is a very big concept in spring. Which spring inherits it from JEE with reference to JSR 330 which makes us to maximize reusability, testability and maintainability of Java code. Before dependency injection has come into picture developers need to write boiler plate code like below, There is a class named Address.java and Person.java the Person.java will take Address.java as property were Person will return all of it state with to String. Lol! you thought that what is the problem with it? there is a problem when we are developing a large enterprise application because there are lots of

Read more

Springcore Constructor and setter injection to pojos

So, in our previous post we have made our basic spring project to say hello, Now in this post we gonna see how to inject values(properties) to the person pojo using spring constructor and setter based injection. Normally in any java based project Constructor based injection is happen at the time of object creation and setter injection happen with java beans by calling methods and then we give properties. But, in spring project what we do is we specify the beans(pojo) properties in beans.xml and the beans are instantiated by spring container with those values. Now we have a pojo

Read more

spring hello world

In this post I am gonna start a new maven project and then I will springify it(making it as spring project) by adding required jars to maven pom.xml. Create a new maven project and start with maven quick start and then add group id and Artifact id(its the project name).   so, we created a new project springhelloworld. pom.xml Person.java beans.xml App.java output: Hello! I’m a person. what we have done is, we created a new project and then created pom.xml which it contains all spring related libraries to getting started with spring, and then create a simple pojo Person.java and

Read more
1 2 3 4