JSR 330 Annotations

Spring 3.0 supports standard JSR 330 Dependency Injection for java. These annotations are scanned the same way as the Spring annotations, only requirement would be to have the relevant jars in your classpath. You can use the following annotations in Spring 3 applications.

  • @Named instead of spring's @Component to declare a bean
  • @Inject instead of spring's @Autowired to inject a bean
Student.java File
package com.jtechies;

import javax.inject.Inject;
import javax.inject.Named;

public class Student {
	private String name;
	private Course course;
	public String getName() {
		return name;
	public void setName(String name) {
		this.name = name;
	public Course getCourse() {
		return course;
	public void setCourse(Course course) {
		this.course = course;
Course.java File
package com.jtechies;

import javax.inject.Named;

public class Course {
	private String name;

	public String getName() {
		return name;
	public void setName(String name) {
		this.name = name;
Test.java File
package com.jtechies.test;

import org.springframework.context
import org.springframework.context.support

import com.jtechies.Course;
import com.jtechies.Student;

public class Test {
	public static void main(String[] args) {
		ConfigurableApplicationContext context = new
		Course course = (Course)context.getBean("course");
		Student student = (Student)
		System.out.println("course name = 
spring.xml File
You also need to add <context:component-scan base-package=" " /> to scan bean annotated with @Named
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

	<!-- base-package indicates where your component stored,
	spring will scan this folder and find out the bean 
	annotated with @Named -->
	<context:component-scan base-package="com.jtechies" />
course name = MCA

Spring v/s JSR 330 Annotations

JSR 330
@Autowired @Inject @Inject has no 'required' attribute to make sure the bean is injected successful.
@Component @Named Spring also scan for @Named.
@Scope @Scope JSR 330 Scope for meta-annotation and injection point only.
@Scope("singleton") @Singleton JSR-330 has scope singleton by default, but you can use Spring's @Scope to define others.
@Qualifier @Named -
@Value No equivalent SpEL specific
@Required Redundant JSR 330 has no 'required' attribute.
@Lazy No equivalent Probably a good thing.