John
John

Reputation:

what is "value" used in @Service annotation

What is the diff between these

@Service(value="test1")

@Service("test1")

Upvotes: 3

Views: 9389

Answers (1)

esaj
esaj

Reputation: 16035

There's no difference, but if the annotation would take more than one parameter, and you wanted to use more than one parameter, you'd need to use the "value="-syntax. For the usage of the parameter, see the @Service-javadoc, or just take a look at the annotation class:

public @interface Service {

    /**
     * The value may indicate a suggestion for a logical component name,
     * to be turned into a Spring bean in case of an autodetected component.
     * @return the suggested component name, if any
     */
    String value() default "";

}

The reason why it's called "value" and why you can omit it can be found from Java annotations documentation:

It is permissible to omit the element name and equals sign (=) in a single-element annotation whose element name is value

Upvotes: 10

Related Questions