java中属性加参数_java – 使用属性文件中的值填充注释参数值

我正在使用Java EE开发一个简单的Web应用程序.我为servlet使用注释,我想用属性文件中的值填充注释的参数,但我不知道如何做到这一点.我想做这样的事情:

// My Servlet

@WebServlet(urlPatterns="${key.value1}")

public class HomeServlet extends MyCustomServlet

{

...

}

# My properties files

key.value1=/home

可能吗 ?如果是,那么解决方案是什么?

谢谢.

解决方法:

这不是直接可能的.您为注释属性提供的值必须是常量.编译代码后无法修改它们.从Java Language Specification

It is a compile-time error if the return type of a method declared in

an annotation type is not one of the following: a primitive type,

String, Class, any parameterized invocation of Class, an enum type

(§8.9), an annotation type, or an array type (§10) whose element type

is one of the preceding types.

但是,如果您控制了它们的处理方式(我不知道您将如何处理它们,因为它们由Servlet容器处理),您可以获取值并执行一些占位符解析.

标签:java,java-ee

来源: https://codeday.me/bug/20190624/1280268.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值