I found that if I use an annotation, the program will not throw a ClassNotFoundException
.
class A {
@Transactional
public void insert() {
//insert something
}
}
Tomcat starts successefully without the javaee-api-7.0.jar which contains the class javax.transaction.Transactional
It makes me very confused, shouldn't the JVM throw a
ClassNotFoundException
when it loads the class A
?
No, it shouldn't. Annotations are just metadata. It's expected that byte-code containing annotations runs fine even if the annotation is not in the classpath. Of course, if some library tries to actually access and use the annotation that is not in the classpath, that won't work.
This is explicitely supported in order to be able, for example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With