Skip to content

ResourceBundle not resolved for spring-security messages if 'spring.messages.basename' is set #7067

@membersound

Description

@membersound

When setting multiple spring message bundles, as advised in https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-internationalization.html:
spring.messages.basename=messages,message-commons

Now if a spring-security error occurs, the spring-security error messages are not loaded correctly. The following warning is printed:

ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en

Interestingly, if you change the properties to a non-existing resource bundle, eg:
spring.messages.basename=messages,message-commons2

Then the warning disappears!

Reproduce as follows:

@SpringBootApplication
public class ResourcebundleFailureApp {
	public static void main(String[] args) {
		SpringApplication.run(ResourcebundleFailureApp.class, args);
	}
}

@RestController
public class TestController {
	@GetMapping("/test")
	public void test() {
	}
}

application.properties:
spring.messages.basename=messages,message-commons2

message-commons.properties (empty)


Unit test:
@RunWith(SpringRunner.class)
@WebMvcTest(TestController.class)
public class ResourceBundleTest {
	@Autowired
	private MockMvc mvc;

	//fails with 401 unauthorized + prints:
	//'ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en'
	@Test
	public void testBundle() throws Exception {
		mvc.perform(MockMvcRequestBuilders.get("/test")).andExpect(status().isUnauthorized());
	}
}

Of course the test succeeds, but in the logs you see ResourceBundleMessageSource error.
resourcebundle-failure.zip

Metadata

Metadata

Assignees

Labels

for: external-projectFor an external project and not something we can fixstatus: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions