views:

248

answers:

4

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.

+1  A: 

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.

Jeff Storey
I wanted to know about the idea of Annotations itself and how does it compare with XML Configuration for Spring Framework and what are the pros and cons of using Annotations as opposed to XML Configuration for Spring Framework ?
Rachel
In Spring, the XML configuration is a bit more verbose, but it keeps Spring specific code out of your codebase. It's a matter of preference, really. XML is more explicit and makes bean definitions very clear whereas a lot of "magic" can happen with the annotations (component scanning, autowiring, etc), and there is often less configuration with annotations.
Jeff Storey
A: 

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.

stacker
+1  A: 

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.

duffymo
Spring Batch and Spring Integration are used in parallel to Spring MVC or they are totally not inter-dependent ?
Rachel
duffymo
A: 

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.