Revert reloadable message source support
Closes gh-14882 See gh-14699 See gh-13377
This commit is contained in:
		
							parent
							
								
									5ac9b972fe
								
							
						
					
					
						commit
						743782de7e
					
				|  | @ -33,8 +33,6 @@ import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.ConditionContext; | ||||
| import org.springframework.context.annotation.Conditional; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.support.AbstractResourceBasedMessageSource; | ||||
| import org.springframework.context.support.ReloadableResourceBundleMessageSource; | ||||
| import org.springframework.context.support.ResourceBundleMessageSource; | ||||
| import org.springframework.core.Ordered; | ||||
| import org.springframework.core.io.Resource; | ||||
|  | @ -67,9 +65,7 @@ public class MessageSourceAutoConfiguration { | |||
| 
 | ||||
| 	@Bean | ||||
| 	public MessageSource messageSource(MessageSourceProperties properties) { | ||||
| 		AbstractResourceBasedMessageSource messageSource = (properties.isReloadable() | ||||
| 				? new ReloadableResourceBundleMessageSource() | ||||
| 				: new ResourceBundleMessageSource()); | ||||
| 		ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); | ||||
| 		if (StringUtils.hasText(properties.getBasename())) { | ||||
| 			messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray( | ||||
| 					StringUtils.trimAllWhitespace(properties.getBasename()))); | ||||
|  |  | |||
|  | @ -71,12 +71,6 @@ public class MessageSourceProperties { | |||
| 	 */ | ||||
| 	private boolean useCodeAsDefaultMessage = false; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Whether to use a "ReloadableResourceBundleMessageSource" rather than the default | ||||
| 	 * "ResourceBundleMessageSource". Recommended during development only. | ||||
| 	 */ | ||||
| 	private boolean reloadable = false; | ||||
| 
 | ||||
| 	public String getBasename() { | ||||
| 		return this.basename; | ||||
| 	} | ||||
|  | @ -125,12 +119,4 @@ public class MessageSourceProperties { | |||
| 		this.useCodeAsDefaultMessage = useCodeAsDefaultMessage; | ||||
| 	} | ||||
| 
 | ||||
| 	public boolean isReloadable() { | ||||
| 		return this.reloadable; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setReloadable(boolean reloadable) { | ||||
| 		this.reloadable = reloadable; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -32,9 +32,6 @@ import org.springframework.context.NoSuchMessageException; | |||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.PropertySource; | ||||
| import org.springframework.context.support.DelegatingMessageSource; | ||||
| import org.springframework.context.support.ReloadableResourceBundleMessageSource; | ||||
| import org.springframework.context.support.ResourceBundleMessageSource; | ||||
| 
 | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
|  | @ -223,38 +220,6 @@ public class MessageSourceAutoConfigurationTests { | |||
| 								.isEqualTo("bar"))); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void testDefaultReloadableValueMessageSource() { | ||||
| 		testReloadableMessageSource(ResourceBundleMessageSource.class, | ||||
| 				"spring.messages.basename:test/messages"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void testNotReloadableMessageSource() { | ||||
| 		testReloadableMessageSource(ResourceBundleMessageSource.class, | ||||
| 				"spring.messages.basename:test/messages", | ||||
| 				"spring.messages.reloadable:false"); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void testReloadableMessageSource() { | ||||
| 		testReloadableMessageSource(ReloadableResourceBundleMessageSource.class, | ||||
| 				"spring.messages.basename:test/messages", | ||||
| 				"spring.messages.reloadable:true"); | ||||
| 	} | ||||
| 
 | ||||
| 	private void testReloadableMessageSource(Class<?> expectedInstance, | ||||
| 			String... propertyValues) { | ||||
| 		this.contextRunner.withPropertyValues(propertyValues).run((context) -> { | ||||
| 			MessageSource messageSource = context.getBean(MessageSource.class); | ||||
| 			if (messageSource instanceof DelegatingMessageSource) { | ||||
| 				messageSource = ((DelegatingMessageSource) messageSource) | ||||
| 						.getParentMessageSource(); | ||||
| 			} | ||||
| 			assertThat(messageSource).isInstanceOf(expectedInstance); | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@PropertySource("classpath:/switch-messages.properties") | ||||
| 	protected static class Config { | ||||
|  |  | |||
|  | @ -73,7 +73,6 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro | |||
| 		properties.put("server.error.include-stacktrace", "ALWAYS"); | ||||
| 		properties.put("server.servlet.jsp.init-parameters.development", "true"); | ||||
| 		properties.put("spring.reactor.stacktrace-mode.enabled", "true"); | ||||
| 		properties.put("spring.messages.reloadable", "true"); | ||||
| 		PROPERTIES = Collections.unmodifiableMap(properties); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -114,17 +114,6 @@ public class DevToolPropertiesIntegrationTests { | |||
| 				.isEqualTo(ErrorProperties.IncludeStacktrace.ALWAYS.toString()); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	public void postProcessEnablesMessageSourceReloadProperty() { | ||||
| 		SpringApplication application = new SpringApplication(TestConfiguration.class); | ||||
| 		application.setWebApplicationType(WebApplicationType.NONE); | ||||
| 		this.context = application.run(); | ||||
| 		ConfigurableEnvironment environment = this.context.getEnvironment(); | ||||
| 		Boolean property = environment.getProperty("spring.messages.reloadable", | ||||
| 				Boolean.class); | ||||
| 		assertThat(property).isTrue(); | ||||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	static class TestConfiguration { | ||||
| 
 | ||||
|  |  | |||
|  | @ -135,7 +135,6 @@ content into your application. Rather, pick only the properties that you need. | |||
| 	spring.messages.cache-duration= # Loaded resource bundle files cache duration. When not set, bundles are cached forever. If a duration suffix is not specified, seconds will be used. | ||||
| 	spring.messages.encoding=UTF-8 # Message bundles encoding. | ||||
| 	spring.messages.fallback-to-system-locale=true # Whether to fall back to the system Locale if no files for a specific Locale have been found. | ||||
| 	spring.messages.reloadable=false # Whether to use a "ReloadableResourceBundleMessageSource" rather than the default "ResourceBundleMessageSource". Recommended during development only. | ||||
| 	spring.messages.use-code-as-default-message=false # Whether to use the message code as the default message instead of throwing a "NoSuchMessageException". Recommended during development only. | ||||
| 
 | ||||
| 	# OUTPUT | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue