bean-validation + spring example

Add bean validation dependency Hibernate provides an implementation of bean-validation. So we will dependent on it. But it has nothing to do with Hiberante ORM. org.hibernate hibernate-validator 5.1.3.Final Create a validator class as a spring bean @Component public class MyBeanValidator { @Resource private Validator validator; public <T> List<String> validateBean(T bean) { List<string> errors = new …

bean-validation + spring example Read More »

How to enable log4j when doing spring-based integration test?

Just put a log4j.xml on test’s class path and log4j will be activated. However, you may hate to have 2 "log4j.xml" in your eclipse. You want the log4j config for testing to be called log4j-test.xml. In that case, do the following: //create your own runner, withen which load log4j public class MySpringJunit4ClassRunner extends SpringJUnit4ClassRunner { …

How to enable log4j when doing spring-based integration test? Read More »

Jersey Client: What if the server side doesn’t return JSON ContentType when it is supposed to?

Your server says it will return JSON string as response, but the ContentType header it sends is not "application/json" but "text/html". What will happen?   Your client will see an exception saying "A message body reader for … was not found" .  What you need to do is to have your own "provider" and let …

Jersey Client: What if the server side doesn’t return JSON ContentType when it is supposed to? Read More »