<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div class="separator" style="clear: both; text-align: center;"><img title="JSR 330 Annotations in Spring" src="https://i0.wp.com/dineshonjava.com/wp-content/uploads/2017/01/inject-named.png" width="640" height="83" border="0" /></div>
<p>Spring provides support for JSR 330 annotations since Spring 3.0. As spring annotations JSR 330 annotations are also working in the spring bean container. You just need to have the relevant jars in your classpath.</p>
<div id="ads-id" align="center"></div>
<p>In <b>pom.xml</b> file add</p>
<pre class="highlight"><;dependency>; 
 <;groupId>;javax.inject<;/groupId>; 
 <;artifactId>;javax.inject<;/artifactId>; 
 <;version>;1<;/version>; 
<;/dependency>; 
</pre>
<div style="background-color: #f2f9fc; border: 1px solid #c9e6f2; border-radius: 3px; padding: 16px; line-height: 1.45;"><span style="color: red; font-size: x-large; text-align: center;"><b>Popular Tutorials</b></span></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/spring-tutorial/"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/"><strong>Spring Boot Tutorial</strong> </a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint/"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/using-spring-jdbc-framework-chapter-32/"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-hateoas-hypermedia-driven-restful-web-service/"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/jax-rs-web-service-tutorial/"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-batch-process-with-example/"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<h2><b>JSR 330 annotations (Dependency Injection):</b></h2>
<ul style="text-align: left;">
<li>Also known as @Inject</li>
<li>Joint JCP effort bu Google and SpringSource</li>
<li>Standardizes internal DI annotations</li>
<li>Published late 2009</li>
</ul>
<h3><b>Dependency Injection with @Inject and @Named</b></h3>
<p>Instead of @Autowired, @javax.inject.Inject may be used as follows:</p>
<pre class="highlight">import javax.inject.Inject; 
import javax.inject.Named; 
@Named 
public class TransferServiceImpl implements TransferService{ 
 
 @Inject 
 public void TransferServiceImpl(@Named("accountRepository") AccountRepository accountRepository ) { 
 this.accountRepository = accountRepository ; 
 } 
 
 } 
 
 
import javax.inject.Named; 
 
@Named("accountRepository") 
public class JdbcAccountRepository implements AccountRepository { 
//... 
} 
</pre>
<ul style="text-align: left;">
<li>As with @Autowired, it is possible to use <b>@Inject</b> at the field level, method level and constructor-argument level.</li>
<li>As with @Component, it is possible to use <b>@Named</b> at the class level for component scanning by @ComponentScan</li>
<li>If you would like to use a qualified name for the dependency that should be injected, you should use the <b>@Named</b> annotation as with @Qualifier.</li>
</ul>
<p><b>Note:</b> In contrast to @Component, the JSR-330 @Named annotation are not composable. Please use Spring’s stereotype model for building custom component annotations.</p>
<p><b>From @Autowired to @Inject</b></p>
<table summary="Spring component model elements vs. JSR-330 variants">
<thead>
<tr bgcolor="#006600">
<th align="center" valign="top">Spring</th>
<th align="center" valign="top">JSR 330</th>
<th align="center" valign="top">Comments</th>
</tr>
</thead>
<tbody>
<tr bgcolor="#999999">
<td align="left" valign="top">
<div style="color: #990000; font-weight: bold;">@Autowired</div>
</td>
<td align="left" valign="top">
<div style="color: blue; font-weight: bold;">@Inject</div>
</td>
<td align="left" valign="top">@Inject always mandatory, has no &#8216;required&#8217; attribute.</td>
</tr>
<tr>
<td align="left" valign="top">
<div style="color: #990000; font-weight: bold;">@Component</div>
</td>
<td align="left" valign="top">
<div style="color: blue; font-weight: bold;">@Named</div>
</td>
<td align="left" valign="top">Spring also scan for @Named .</td>
</tr>
<tr bgcolor="#999999">
<td align="left" valign="top">@Scope</td>
<td align="left" valign="top">@Scope</td>
<td align="left" valign="top">JSR 330 Scope for ,eta annotation and injection point only</td>
</tr>
<tr>
<td align="left" valign="top">
<div style="color: #990000; font-weight: bold;">@Scope(&#8220;singleton&#8221;)</div>
</td>
<td align="left" valign="top">
<div style="color: #0000cc; font-weight: bold;">@Singleton</div>
</td>
<td align="left" valign="top">JSR-330 default scope is like Spring’s prototype.</td>
</tr>
<tr bgcolor="#999999">
<td align="left" valign="top">
<div style="color: #990000; font-weight: bold;">@Qualifier</div>
</td>
<td align="left" valign="top">
<div style="color: blue; font-weight: bold;">@Named</div>
</td>
<td align="left" valign="top"></td>
</tr>
<tr>
<td align="left" valign="top">
<div style="color: #990000; font-weight: bold;">@Value</div>
</td>
<td align="left" valign="top">No equivalent</td>
<td align="left" valign="top">SpEL specific</td>
</tr>
<tr bgcolor="#999999">
<td align="left" valign="top">
<div style="color: #990000; font-weight: bold;">@Required</div>
</td>
<td align="left" valign="top">Redundant</td>
<td align="left" valign="top">@Inject always required</td>
</tr>
<tr>
<td align="left" valign="top">
<div style="color: #990000; font-weight: bold;">@Lazy</div>
</td>
<td align="left" valign="top">No equivalent</td>
<td align="left" valign="top">Useful when needed, often abused</td>
</tr>
</tbody>
</table>
<p> ;</p>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px;"><span style="color: red; font-size: x-large; text-align: center;"><b>Spring Related Topics you may like</b></span></p>
<ul>
<li><b><a href="https://dineshonjava.com/interview-questions-on-spring/"><span style="color: red;">Spring Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-interview-questions-and-answers/"><span style="color: red;">Spring AOP Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-interview-questions-and-answers/"><span style="color: red;">Spring MVC Interview Questions</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-interview-questions-and-answers/"><span style="color: red;">Spring Security Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-rest-web-services-interview-questions-and-answers/"><span style="color: red;">Spring REST Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-boot-interview-questions-and-answers/"><span style="color: red;">Spring Boot Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-boot-microservices-interview-questions-answers/"><span style="color: red;">Spring Boot Microservices Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/dependency-injection-in-spring/"><span style="color: red;">Dependency Injection (DI) in Spring </span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-ioc-container/"><span style="color: red;">Spring IoC Container</span></a></b></li>
<li><b><a href="https://dineshonjava.com/what-is-bean-factory-in-spring/"><span style="color: red;">What is Bean Factory in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/application-context-in-spring/"><span style="color: red;">ApplicationContext in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/bean-autowiring-in-spring/"><span style="color: red;">Bean Autowiring in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/understanding-bean-scopes/"><span style="color: red;">Spring Bean Scopes</span></a></b></li>
<li><b><a href="https://dineshonjava.com/create-custom-bean-scope-in-spring-example/"><span style="color: red;">Create Custom Bean Scope in Spring Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/using-applicationcontextaware-in-spring/"><span style="color: red;">Using ApplicationContextAware in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/bean-lifecycle-and-callbacks/"><span style="color: red;">Spring Bean Life Cycle and Callbacks</span></a></b></li>
<li><b><a href="https://dineshonjava.com/writing-beanpostprocessor-in-spring/"><span style="color: red;">BeanPostProcessor in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/writing-beanfactorypostprocessor-in/"><span style="color: red;">BeanFactoryPostProcessor in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/annotations-in-spring-and-based/"><span style="color: red;"> Annotations in Spring and Based Configuration</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-jsr-250-annotations/"><span style="color: red;">Spring JSR-250 Annotations</span></a></b></li>
<li><b><a href="https://dineshonjava.com/jsr-330-annotations-in-spring/"><span style="color: red;">JSR 330 Annotations in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/stereotype-annotations-in-spring/"><span style="color: red;">Spring @Component, @Repository, @Service and @Controller Stereotype Annotations</span></a></b></li>
<li><b><a href="https://dineshonjava.com/method-injection-with-spring-using-lookup-method-property/"><span style="color: red;">Method injection with Spring using Lookup method property</span></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-aop-in-spring/"><span style="color: red;">Spring AOP-Introduction to Aspect Oriented Programming</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aspect-annotation/"><span style="color: red;">@Aspect Annotation in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-before-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @Before Annotation Advice Example<br />
</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-before-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP Before Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-after-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @After Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-after-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP After Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-after-returning-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @AfterReturning Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-after-returning-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP After-Returning Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-after-throwing-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @AfterThrowing Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-after-throwing-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP After Throwing Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-around-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @Around Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-around-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP Around Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/understanding-aop-proxies-chapter-31/"><span style="color: red;">Spring AOP Proxies in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-transaction-management-in/"><span style="color: red;"> Spring AOP Transaction Management in Hibernate</span></a></b></li>
<li><b><a href="https://dineshonjava.com/transaction-management-in-spring/"><span style="color: red;">Spring Transaction Management</span></a></b></li>
<li><b><a href="https://dineshonjava.com/declarative-transaction-management/"><span style="color: red;">Spring Declarative Transaction Management Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-ordering-of-aspects-with-example/"><span style="color: red;">Spring AOP-Ordering of Aspects with Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-java-based-configuration-with-example/"><span style="color: red;">Spring Security Java Based Configuration with Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-xml-namespace-configuration-example/"><span style="color: red;">Spring Security XML Namespace Configuration Example</span></a></b></li>
</ul>
<p> ;</p>
</div>
</div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/what-is-meant-by-application-context-and-how-do-you-create-one/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/container-managed-transaction-cmt-on-ejb-and-spring-declarative-transaction/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '99'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…