File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Autowiring does not work inside custom constraint validator using Spring-Test-MVC

 
Darren Carter
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eveyone,

I have posted this in the Spring forums but have not had a reply. Can anyone help with this please..?

I have an issue with autowiring inside a custom constraint validator when running an integration test using spring-test-mvc. The service I require is null.

However when I run the web app, its is auotwired correctly.

Custom Constraint Validator (Booking Service is null!)



Annotation


Service


Unit Test



Config



Controller


 
Darren Carter
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

With Thanks to Rossen Stoyanchev I have this working.

In short the problem is to do with standloneSetup with does not load spring configuration.

One option is to create a LocalValidatorFactoryBean configured with a SpringConstraintValidatorFactory and plug it into the standaloneSetup builder.

However I decided to migrate from spring-test-mvc to spring-test in 3.2.

All that was required was to annotate my test class with @WebAppConfiguration, load in my spring configuration files with @ContextConfiguration and then @Autowired WebApplicationContext

Example




I can now @Autowire services in my custom jsr annotation validator.

Hope this helps others

Regards
Darren C.


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic