Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are annotations and how do they actually work for frameworks like Spring?

I am new to Spring and now a days I hear a lot about Spring Framework. I have two sets of very specific questions:

Set No. 1:

  • What are annotations in general ?

  • How does annotations works specifically with Spring framework ?

  • Can annotations be used outside Spring Framework or are they Framework specific ?

Set No. 2:

  • What module of Spring Framework is widely used in Industry ?

  • I think it is Spring MVC but why it is the most used module, if am correct or correct me on this ?

I am newbie to Spring and so feel free to edit this questions to make more sense.

like image 760
Rachel Avatar asked May 09 '10 15:05

Rachel


People also ask

What are annotations in Spring framework?

Spring Annotations allows us to configure dependencies and implement dependency injection through java programs.

How are annotations used in a Spring application?

Spring Boot Annotations is a form of metadata that provides data about a program. In other words, annotations are used to provide supplemental information about a program. It is not a part of the application that we develop. It does not have a direct effect on the operation of the code they annotate.

How the annotation works in Java?

In Java, annotations are metadata about the source code. They do not have any direct effect on the execution of the Java program. Annotations in Java were introduced in JDK 5. The main purpose of using annotation is that it gives instructions to the compiler at the build-time and at the runtime of program execution.

What is Spring framework and how it works?

The Spring Framework (Spring) is an open-source application framework that provides infrastructure support for developing Java applications. One of the most popular Java Enterprise Edition (Java EE) frameworks, Spring helps developers create high performing applications using plain old Java objects (POJOs).


2 Answers

What are annotations in general?

Annotations can be thought of as meta-data for classes.

How does annotations works specifically with Spring framework?

Spring uses annotations as an alternative to XML for declarative configuration. Some people don't like XML.

Can annotations be used outside Spring Framework or are they Framework specific?

You need the implementation JARs to use any annotation, so if you use the annotations you are using Spring. Annotations are a general idea introduced into Java 5. You can write your own as well.

What module of Spring Framework is widely used in Industry?

Spring Core is used by all the other modules; hence the name.

I think it is Spring MVC but why it is the most used module, if am correct or correct me on this ?

Absolutely incorrect. Spring MVC has lots of competitors (e.g., Struts 1 and 2, JSF, Wicket, Flex, etc.), so it's not always the first choice for web MVC. And all apps that use Spring aren't web apps. Spring Batch and Integration are quite popular and growing.

like image 138
duffymo Avatar answered Oct 25 '22 10:10

duffymo


Annotations were introduced in Java 5 http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html and are not Spring specific. In general, annotations allow you to add metadata to a class, method or variable. An annotation can be interpreted by the compiler (for example, the @Override annotation) or by a framework such as spring (for example, the @Component annotation).

Spring has many different annotations, so you would need to be more specific about which annotations you have questions about. But Spring annotations can only be used within Spring, and other annotations can be used within other frameworks.

For Set No 2 of questions, that should be opened as a second questions since it doesn't relate to the annotations.

like image 30
Jeff Storey Avatar answered Oct 25 '22 09:10

Jeff Storey