-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Alex Landini opened SPR-6817 and commented
I have a Spring MVC portlet with one spring configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan
base-package="com.cedac.liferay.calcoli.portlets.ammortamenti" />
<mvc:annotation-driven conversion-service="conversionService" validator="validatorJSR303"/>
<!-- VIEW RESOLUTION AND RENDERING -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="views"/>
</bean>
<!-- Message Bundle -->
<!-- Message source for this context, loaded from localized "messages_xx" files -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
<value>com.cedac.liferay.calcoli.portlets.ammortamenti.messages</value>
</list>
</property>
</bean>
</beans>
and a global spring mvc configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!--
Conversion service
Supporta anche le annotazioni per la formattazione
-->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
</bean>
<!-- Validation JSR 303 -->
<bean id="validatorJSR303" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
</beans>
both of them are correctly loaded but when I debug the above method in the controller, conversion service and validator are null.
@InitBinder
public void initBinder(WebDataBinder binder) {
}
I have to autowire the beans and set them into the binder:
@Autowired
private AmmortamentiService ammortamentiService;
@Autowired
private Validator validator;
@InitBinder
public void initBinder(WebDataBinder binder) {
//Conversion Service
binder.setConversionService(conversionService);
//Validator
binder.setValidator(ammortamentoValidator);
}
Affects: 3.0 GA
Issue Links:
- Update documentation with example of single ApplicationContext per webapp [SPR-11703] #16325 Update documentation with example of single ApplicationContext per webapp
15 votes, 12 watchers