访问服务本身中的春季服务名称

发布于 2025-01-24 14:32:30 字数 315 浏览 2 评论 0原文

我很难做我认为很容易的事情。 我有一项服务:

@Service("tr_v1_mapper")
@RequiredArgsConstructor
@Slf4j
public class VoneMapper implements GenericMapper{
// Mapping code ...

// Service name
  String serviceName = "tr_v1_mapper"
}

基本上,我想将我的服务名称存储在vonemapper中的字符串变量中,而无需对其进行编码。 有可能吗? 感谢您的帮助。

下午

I am having some difficulties to do something I thought would be easy.
I have a service:

@Service("tr_v1_mapper")
@RequiredArgsConstructor
@Slf4j
public class VoneMapper implements GenericMapper{
// Mapping code ...

// Service name
  String serviceName = "tr_v1_mapper"
}

Basically, I want to stock my service name in a String variable inside my class VoneMapper without harcoding it.
is it something possible ?
Thanks by advance for your help.

PM

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山人契 2025-01-31 14:32:30

在注释中使用常数怎么办?更多信息在此处: https://wwww.baeldung.com/java-annotung.com/java-annotation-anotation-com-属性 - 价值限制

@Service(VoneMapper.SERVICE_NAME)
@RequiredArgsConstructor
@Slf4j
public class VoneMapper implements GenericMapper {
// Mapping code ...

    // Service name
    static final String SERVICE_NAME = "tr_v1_mapper";
}

What about using a constant in the annotation? More info here: https://www.baeldung.com/java-annotation-attribute-value-restrictions

@Service(VoneMapper.SERVICE_NAME)
@RequiredArgsConstructor
@Slf4j
public class VoneMapper implements GenericMapper {
// Mapping code ...

    // Service name
    static final String SERVICE_NAME = "tr_v1_mapper";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文