aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Autowiring does not work inside custom constraint validator using Spring-Test-MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Autowiring does not work inside custom constraint validator using Spring-Test-MVC" Watch "Autowiring does not work inside custom constraint validator using Spring-Test-MVC" New topic
Author

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

Darren Carter
Ranch Hand

Joined: Jul 08, 2010
Posts: 30
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

Joined: Jul 08, 2010
Posts: 30
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
 
subject: Autowiring does not work inside custom constraint validator using Spring-Test-MVC