Bilgehan
Bilgehan

Reputation: 1227

Spring Boot @Service annotation in extended class

Hi I have BaseClass and It contains @Service annotation.I want to extend all my class from this class But In MyExtendedClass @Autowired or other aspect content are not working until I add @Service attribute to my ExtendedClass.Why is this necessary?Is there another method to avoid duplicate attribute?What I want to do is put all my attributes to base class.

@Service
public class MyBase {
    public MyBase {
    }
}

//Normally it doesnt have @Service annotation but not work 
public class MyExtendedClass extends MyBase 

Upvotes: 1

Views: 2241

Answers (1)

Matheus
Matheus

Reputation: 3370

From Spring Framework Javadoc on @Service annotation:

The @Service is defined as below:

@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Component
public @interface Service

The @Service annotation is not marked with the @Inherited annotation. This means that this annotation will not be automatically inherited from super classes marked with it to the child classes.

Upvotes: 3

Related Questions