开发者

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 qu开发者_如何学编程estions:

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.


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.


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 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.


What are annotations in general ?

Annotations are a convienient way of configuration, which could also be done using explicit configuration files, like deployment descriptors.

How does annotations works specifically with Spring framework ?

In spring they are used for dependency injection and many other purposes

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

Yes you can even write your own annotations. They have been introduced in java 1.5 for i.g. suppresing warnings.

What module of Spring Framework is widely used in Industry ?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜