[Java] 用 junit 做自動化測試, 要使用 Bean Validation (JSR 303)
如果你有使用 如下的 @Bean(name = "methodValidationPostProcessor") public MethodValidationPostProcessor methodValidationPostProcessor() { MethodValidationPostProcessor processor = new MethodValidationPostProcessor(); processor.setValidatorFactory(localValidatorFactoryBean()); return processor; } Bean Validation , 那你一定要指定你的EL , 如果沒有指定,去使用 Junit4 去跑會出現以下的錯誤 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:161) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:101) at org.springframework.test.context.TestContextMana...