{"id":101274,"date":"2020-01-09T10:00:30","date_gmt":"2020-01-09T08:00:30","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=101274"},"modified":"2020-01-08T12:38:50","modified_gmt":"2020-01-08T10:38:50","slug":"method-parameter-validation-with-spring-and-jsr-303","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html","title":{"rendered":"Method parameter validation with Spring and JSR 303"},"content":{"rendered":"<p>Spring provides an easy way to validate method parameters using <a href=\"https:\/\/beanvalidation.org\/\">JSR 303 bean validation<\/a>. In this post we will see how to use this feature.<\/p>\n<h2 class=\"wp-block-heading\">Setup<\/h2>\n<p>First we need to add support for method parameter validation by creating a MethodValidationPostProcessor bean:<\/p>\n<div>\n<div id=\"highlighter_780453\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java color1\">@Configuration<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java keyword\">public<\/code>&nbsp;<code class=\"java keyword\">class<\/code>&nbsp;<code class=\"java plain\">MyConfiguration&nbsp;{<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java color1\">@Bean<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">public<\/code>&nbsp;<code class=\"java plain\">MethodValidationPostProcessor&nbsp;methodValidationPostProcessor()&nbsp;{<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">return<\/code>&nbsp;<code class=\"java keyword\">new<\/code>&nbsp;<code class=\"java plain\">MethodValidationPostProcessor();<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\">Validating method parameters<\/h2>\n<p>After registering the MethodValidationPostProcessor we can enable method parameter validation per bean by adding the @Validated annotation. Now we can add Java Bean validation annotations to our method parameter to perform validation.<\/p>\n<div>\n<div id=\"highlighter_198914\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java color1\">@Service<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java color1\">@Validated<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java keyword\">public<\/code>&nbsp;<code class=\"java keyword\">class<\/code>&nbsp;<code class=\"java plain\">UserService&nbsp;{<\/code><\/div>\n<div class=\"line number4 index3 alt1\">&nbsp;<\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">public<\/code>&nbsp;<code class=\"java plain\">User&nbsp;getUser(<\/code><code class=\"java color1\">@NotBlank<\/code>&nbsp;<code class=\"java plain\">String&nbsp;uuid)&nbsp;{<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">...<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Here we added a @NotBlank annotation to make sure the passed uuid parameter is not null or an empty string. Whenever an invalid uuid is passed a ContraintViolationException will be thrown.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Besides simple parameter validation we can also validate objects annotated with JSR 303 annotations.<\/p>\n<p>For example:<\/p>\n<div>\n<div id=\"highlighter_533124\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\">public<\/code>&nbsp;<code class=\"java keyword\">class<\/code>&nbsp;<code class=\"java plain\">User&nbsp;{<\/code><\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;<\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java color1\">@NotBlank<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">private<\/code>&nbsp;<code class=\"java plain\">String&nbsp;name;<\/code><\/div>\n<div class=\"line number5 index4 alt2\">&nbsp;<\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java comments\">\/\/&nbsp;getter&nbsp;+&nbsp;setter<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div>\n<div id=\"highlighter_192175\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java color1\">@Service<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java color1\">@Validated<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java keyword\">public<\/code>&nbsp;<code class=\"java keyword\">class<\/code>&nbsp;<code class=\"java plain\">UserService&nbsp;{<\/code><\/div>\n<div class=\"line number4 index3 alt1\">&nbsp;<\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">public<\/code>&nbsp;<code class=\"java keyword\">void<\/code>&nbsp;<code class=\"java plain\">createUser(<\/code><code class=\"java color1\">@Valid<\/code>&nbsp;<code class=\"java plain\">User&nbsp;user)&nbsp;{<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">...<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>By adding @Valid (not @Validated) we mark the user parameter for validation. The passed user object will then be validated based on the validation constraints defined in the User class. Here the name field should not be null or contain an empty string.<\/p>\n<h2 class=\"wp-block-heading\">How does this work?<\/h2>\n<p>The MethodValidationPostProcessor bean we registered is a BeanPostProcessor that checks each bean if it is annotated with @Validated. If thats the case it will add an AOP interceptor (<a href=\"https:\/\/docs.spring.io\/spring\/docs\/current\/javadoc-api\/org\/springframework\/validation\/beanvalidation\/MethodValidationInterceptor.html\">MethodValidationInterceptor<\/a>) to intercept method calls and performs validation. The actual bean method is only called if the validation was successful.<\/p>\n<p>Because this feature relies on AOP interceptors it works only on spring beans.<\/p>\n<p>As always you can find the sources for the shown examples on <a href=\"https:\/\/github.com\/mscharhag\/blog-examples\/tree\/master\/spring-method-parameter-validation\">GitHub<\/a>.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Michael Scharhag, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener noreferrer\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/www.mscharhag.com\/spring\/spring-method-parameter-validation\" target=\"_blank\" rel=\"noopener noreferrer\">Method parameter validation with Spring and JSR 303<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring provides an easy way to validate method parameters using JSR 303 bean validation. In this post we will see how to use this feature. Setup First we need to add support for method parameter validation by creating a MethodValidationPostProcessor bean: 1 2 3 4 5 6 7 @Configuration public&nbsp;class&nbsp;MyConfiguration&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;@Bean &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;MethodValidationPostProcessor&nbsp;methodValidationPostProcessor()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;new&nbsp;MethodValidationPostProcessor(); &nbsp;&nbsp;&nbsp;&nbsp;} } &hellip;<\/p>\n","protected":false},"author":514,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-101274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Method parameter validation with Spring and JSR 303 - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about JSR 303? Check our article explaining how to provide an easy way to validate method parameters using JSR 303 bean validation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Method parameter validation with Spring and JSR 303 - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about JSR 303? Check our article explaining how to provide an easy way to validate method parameters using JSR 303 bean validation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-09T08:00:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Scharhag\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/mscharhag\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Scharhag\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html\"},\"author\":{\"name\":\"Michael Scharhag\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0f0f81e875d40e3f820392e0ffce65d1\"},\"headline\":\"Method parameter validation with Spring and JSR 303\",\"datePublished\":\"2020-01-09T08:00:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html\"},\"wordCount\":307,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html\",\"name\":\"Method parameter validation with Spring and JSR 303 - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2020-01-09T08:00:30+00:00\",\"description\":\"Interested to learn about JSR 303? Check our article explaining how to provide an easy way to validate method parameters using JSR 303 bean validation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/01\\\/method-parameter-validation-with-spring-and-jsr-303.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Method parameter validation with Spring and JSR 303\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0f0f81e875d40e3f820392e0ffce65d1\",\"name\":\"Michael Scharhag\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g\",\"caption\":\"Michael Scharhag\"},\"description\":\"Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.\",\"sameAs\":[\"http:\\\/\\\/www.mscharhag.com\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/mscharhag\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/michael-scharhag\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Method parameter validation with Spring and JSR 303 - Java Code Geeks","description":"Interested to learn about JSR 303? Check our article explaining how to provide an easy way to validate method parameters using JSR 303 bean validation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html","og_locale":"en_US","og_type":"article","og_title":"Method parameter validation with Spring and JSR 303 - Java Code Geeks","og_description":"Interested to learn about JSR 303? Check our article explaining how to provide an easy way to validate method parameters using JSR 303 bean validation.","og_url":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-01-09T08:00:30+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Michael Scharhag","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/mscharhag","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Michael Scharhag","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html"},"author":{"name":"Michael Scharhag","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0f0f81e875d40e3f820392e0ffce65d1"},"headline":"Method parameter validation with Spring and JSR 303","datePublished":"2020-01-09T08:00:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html"},"wordCount":307,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html","url":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html","name":"Method parameter validation with Spring and JSR 303 - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2020-01-09T08:00:30+00:00","description":"Interested to learn about JSR 303? Check our article explaining how to provide an easy way to validate method parameters using JSR 303 bean validation.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2020\/01\/method-parameter-validation-with-spring-and-jsr-303.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Method parameter validation with Spring and JSR 303"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0f0f81e875d40e3f820392e0ffce65d1","name":"Michael Scharhag","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g","caption":"Michael Scharhag"},"description":"Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.","sameAs":["http:\/\/www.mscharhag.com\/","https:\/\/x.com\/https:\/\/twitter.com\/mscharhag"],"url":"https:\/\/www.javacodegeeks.com\/author\/michael-scharhag"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/101274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/514"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=101274"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/101274\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=101274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=101274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=101274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}