第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何閱讀注解中的messages.properties

如何閱讀注解中的messages.properties

www說(shuō) 2022-05-20 18:37:51
我想使用本地化來(lái)本地化 Swagger 文檔。但我只能為 Annotations 提供編譯時(shí)常量。所以我很困惑如何提供來(lái)自 messages_**.properties 的讀取消息并將其提供給注釋。消息來(lái)源:@Configurationpublic class CustomMessageSourceConfig {    @Bean    public MessageSource messageSource() {        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();        messageSource.setBasename("classpath:messages");        messageSource.setDefaultEncoding("UTF-8");        return messageSource;    }    @Bean    public LocalValidatorFactoryBean getValidator() {        LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();        bean.setValidationMessageSource(messageSource());        return bean;    }    @Bean    public LocaleResolver localeResolver() {        SessionLocaleResolver slr = new SessionLocaleResolver();        slr.setDefaultLocale(Locale.ENGLISH);        return slr;    }}從 messages_**.properties 中讀取消息:@Componentpublic class MessagesByLocaleServiceImpl implements MessagesByLocaleService {    @Autowired    private MessageSource messageSource;    @Override    public String getMessage(String id) {        Locale locale = LocaleContextHolder.getLocale();        return StringEscapeUtils.unescapeJava(messageSource.getMessage(id, null, locale));    }}這是我在 Java 代碼中閱讀消息的方式:@Bean    public Docket api() {        return new Docket(DocumentationType.SWAGGER_2).select()                .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot"))).build()                .apiInfo(apiInfo())                .tags(new Tag("Netmap Mode Service", messageSource.getMessage(MessageCodes.SWAGGER_WINDOWS_ONLY)));    }    private ApiInfo apiInfo() {        return new ApiInfoBuilder().title(messageSource.getMessage(MessageCodes.SWAGGER_TITLE))                .description(messageSource.getMessage(MessageCodes.SWAGGER_DESCRIPTION))                .contact(messageSource.getMessage(MessageCodes.SWAGGER_CONTACT)).build();    }我想閱讀這些注釋中的消息。任何指導(dǎo)或建議將不勝感激。
查看完整描述

2 回答

?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

最好將文檔注釋與代碼分離(從外部屬性文件中讀取文本而不是作為純文本插入)

像這樣使用占位符,而不是

@ApiOperation(value = "Add Netmap mode " ,...)

采用

@ApiOperation(value = ${message.addNetMode} ,...)

在“messages_**.properties”文件里面應(yīng)該有鍵值對(duì)

message.addNetMode=Add Netmap mode

還要在類級(jí)別的配置中注冊(cè)屬性文件

@PropertySource("classpath:messages_**.properties")

**請(qǐng)注意,可能不支持某些注釋的值。請(qǐng)參閱文檔http://springfox.github.io/springfox/docs/current/#support-for-documentation-from-property-file-lookup


查看完整回答
反對(duì) 回復(fù) 2022-05-20
?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

application.properties您可以使用SPELie獲取值${}

@Annotation(value="${request.reminder.mails.cron.expression}")

注意:- 道具名稱應(yīng)該是完整的名稱application.properties


查看完整回答
反對(duì) 回復(fù) 2022-05-20
  • 2 回答
  • 0 關(guān)注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)