简体   繁体   中英

Can @ApplicationPath annotation be used on interface?

According to JAXRS spec, is @ApplicationPath can be used on interface?

import javax.ws.rs.ApplicationPath;

@ApplicationPath("/")
public interface TestRes {

}

Compiler dont have a problem with that. But is this good approach?

ApplicationPath Documentation cleary says it is only applicable for subclass of javax.ws.rs.core.Application so if you apply on the interface it will not work, so when you deploy you might end up with this error message The ResourceConfig instance does not contain any root resource classes."

Identifies the application path that serves as the base URI for all resource URIs provided by Path. May only be applied to a subclass of Application.

jaxrs

The @ApplicationPath annotation is used to define the URL mapping for the application. The path specified by @ApplicationPath is the base URI for all resource URIs specified by @Path annotations in the resource class. You may only apply @ApplicationPath to a subclass of javax.ws.rs.core.Application.

您的类必须扩展Application以便它不能在接口上使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM