kotlin - 有什么方法可以在 init 块或其他函数中执行 jax-rs 方法?
问题描述
目前,我使用一种架构通过 jax 使用 @get、@post 等方法创建 cruds
@Path("/users")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
class UsersService @Inject constructor(
val users: Users,
userDTOMapper: UserDTOMapper
) : CrudService<User, UserDTO, UserDTO>(
repository = users,
mapper = userDTOMapper
)
但是,我想删除这种继承并使用聚合以获得更好的灵活性。可以有这样的东西
@Path("/users")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
class UsersService @Inject constructor(
val users: Users,
userDTOMapper: UserDTOMapper
) {
init {
withReadOnlyOperations()
// @GET
// fun anotherTestMethod() : String{
// return "Here JAX-RS can't find the method ;/"
// }
}
}
fun withReadOnlyOperations() {
@GET
fun readOnlyOperationTest() : String{
return "hey"
}
}
有什么方法可以使用其他函数,或者在我手动定义的上下文中初始化路由?
我知道你可以使用接口,但是我仍然会生成一个我必须为使用这个接口的每个实体实现的 boiderplate 代码,已经有了继承/聚合模型,我已经有了定义好的方法并准备好使用。
解决方案
推荐阅读
- apache-spark - Apache Beam Metrics Counter 使用 SparkRunner 给出不正确的计数
- git - git --format,例如 `log` 和 `tag -l`:格式说明符是否相同,它们在哪里描述?
- mysql - 为什么 MySQL 不使用 UNIQUE KEY?
- azure-devops - How to get matrix's job's name in the steps part of the yaml file?
- google-cloud-platform - 使用 LFTP 将数据从 SFTP 同步到 Google Cloud Storage
- regex - 正则表达式匹配不应该的东西
- python - Doc2Vec infer_vector 未按预期工作
- javascript - 变量中未接收到数据时隐藏模式
- node.js - 无需链接即可连接 docker compose 容器
- python - 选择特定时间之间的所有记录?