简体   繁体   中英

Can spring.messages.basename be an IP Address

The spring.messages.basename is set to an IP address like:

spring:
  messages:
    basename: http://1.2.3.4:8888/messages.properties 

That is the IP of a spring cloud config server. When the app starts up, it's trying to send a request to that url but with all dots being replaced by slashes:

s.n.www.protocol.http.httpurlconnection  : ProxySelector Request for http://1/2/3/4:8888/messages.properties

As the IP address is messed up, the connection hangs and the app could not start up properly.

Debugging into the source code, this method org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration.ResourceBundleCondition#getResources is found being responsible for the corrupted IP.

org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration.ResourceBundleCondition#getResources

Additionally, there is already a messageSource bean in the app configuration like:

@Bean(name = "messageSource")
public MessageSource messageSource(@Value("${spring.messages.basename:}") String basename) {
 ...
}

Hence, when configuring a timeout for that malformed URL request, the app can still start up successfully and with the proper message loaded.

So the questions are:

  1. Why is the MessageSourceAutoConfiguration trying to send a request for resources supposed to be in the classpath (That method is trying to get resources from classpath)?
  2. Should the MessageSourceAutoConfiguration load the message resource when there is already a bean created for that?
  3. How to disable the MessageSourceAutoConfiguration or get rid of the malformed IP request without having to put a timeout for it?
  4. Is it valid to set spring.messages.basename to an IP Address?

spring-boot version: 2.6.6 spring version: 5.3.18

Thank you in advance for you help.

You cannot specify a URL for spring.messages.basename . See this page where it says:

spring.messages.basename supports comma-separated list of locations, either a package qualifier or a resource resolved from the classpath root.

It is a resource name pointing to a file inside the classpath, not a URL.

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