Dachstein
Dachstein

Reputation: 4282

How Hibernate Validation message pulled from messages.properties in Spring?

@Size(message = "coming from messages.properties")
private String name;

How a message can be pulled from messages.properties in Spring Boot?

Upvotes: 0

Views: 243

Answers (2)

Vy Do
Vy Do

Reputation: 52516

It works by implements of interface org.springframework.context.MessageSource, these are:

  • org.springframework.context.support.ResourceBundleMessageSource or

  • org.springframework.context.support.ReloadableResourceBundleMessageSource

You can attach Spring Framework's source code, place break points, then debug to see how it works under the hood.

Hibernate validators get message like almost other Java application. Spring Framework processed it before it called by Hibernate validators.

Reference: http://docs.spring.io/spring-framework/docs/current/javadoc-api/index.html?org/springframework/context/MessageSource.html

Upvotes: 0

Bhushan Uniyal
Bhushan Uniyal

Reputation: 5703

hibernate default search message key value in ValidationMessages.properties file so add ValidationMessages.properties in your resource path

Add you message key value in ValidationMessages.properties e.g->

coming.from.messages.properties=coming from messages.properties

and in your class validation:

 @Size(message = "coming.from.messages.properties")
    private String name;

Upvotes: 1

Related Questions