Spring EL in Annotation or (Annotation-based configuration) by R4R Team

Spring EL in Annotation(Annotation-based configuration):-
The @Value annotation can be placed on fields, methods and method/constructor parameters to specify a default value.
1 This is the first class . 

package com.r4r.in;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Component;

@Component("studBean")

public class Student {

@Value("#{empBean}")

private Name name;

@Value("#{empBean.name}")

private String studName;

//...

}

2 This is second class.

package com.r4r.in;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Component;

@Component("empBean")

public class Employee {

@Value("vipul") //inject String directly

private String name;

@Value("20") //inject interger directly

private int age;

public String getName() {

return name;

}

//...

}

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!