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.
Annotations in Java programing language is a special form of metadata that can be embedded in Java source code. The use of annotations in Java language is introduced in Java 5.0 ie Java 5 provides metdata support at language level.
In Spring, XML based configurations is the most popular configuration style.. Then annotation based configuration style came which enables users to configure beans inside the java source file itself. Spring framework provides different custom java5+ annotations. These annotations can be used in transactional demarcation, aop, JMX etc. There are core Spring Annotations, Spring MVC Annotations, AspectJ Annotations, JSR-250 Annotations, Testing Annotations etc. Both xml based configurations and Annotations have pros and cons. I would suggest mixing the two.
The custom Spring annotations are framework specific. But you can write your own annotations also.
The Core container module is the most important module which handles the basic principle of Dependency Injection and it's used in all other modules in the framework. Spring MVC is only a web MVC framework built on Spring's core functionality.
You can go through Spring documentation and books like Spring in Action and Spring Recipes to get a good idea about the framework.
Annotations are a convienient way of configuration, which could also be done using explicit configuration files, like deployment descriptors.
In spring they are used for dependency injection and many other purposes
Yes you can even write your own annotations. They have been introduced in java 1.5 for i.g. suppresing warnings.
The spring core module is used in all applications and therefore mostly used.
You should also browse the Documentation to get a first impression what the spring framework and its modules cover.
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.
Annotations can be thought of as meta-data for classes.
Spring uses annotations as an alternative to XML for declarative configuration. Some people don't like XML.
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.
Spring Core is used by all the other modules; hence the name.
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.