We can inject java.util.Properties bean in Spring with a PropertiesFactoryBean. Here is how I did for my mybatis setting values.
<!-- mybatist setting properties -->
<bean id="mybatisConfigrations" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="cacheEnabled">true</prop>
<prop key="safeRowBoundsEnabled">true</prop>
</props>
</property>
</bean>
Wednesday, October 9, 2013
Thursday, August 15, 2013
How to integrate Oval validation with Spring 3
The way I see it. If you are currently doing validation in a spring mvc application by implementing
interface Validator undestanding spring oval intergration is supper easy. Anyway it doesn't matter you have any experiance on that or not you will understand how spring oval intergration can do at with this tutorial.
Need of a validator interface
public interface Validator {
boolean supports(Class clazz);
void validate(Object target, Errors errors);
}
Spring API to validate
Add this to your bean configuration file. Replace the highlighted configuration files with your ones.
<bean id="validator" class="net.sf.oval.integration.spring.SpringValidator">
<constructor-arg>
<bean id="validator" class="net.sf.oval.Validator">
<constructor-arg>
<util:list>
<bean class="net.sf.oval.configuration.xml.XMLConfigurer">
<constructor-arg>
<value type="java.io.InputStream">classpath:com/test/validation/oval1-config.xml</value>
</constructor-arg>
</bean>
<bean class="net.sf.oval.configuration.xml.XMLConfigurer">
<constructor-arg>
<value type="java.io.InputStream">classpath:com/test/validation/oval2-config.xml</value>
</constructor-arg>
</bean>
</util:list>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
The class net.sf.oval.integration.spring.SpringValidator provides an implementation of Spring's org.springframework.validation.Validatorinterface and thus can be used for Spring Validation.
interface Validator undestanding spring oval intergration is supper easy. Anyway it doesn't matter you have any experiance on that or not you will understand how spring oval intergration can do at with this tutorial.
- Oval what is oval?
- Oval validation
- spring support
- oval class API
Need of a validator interface
public interface Validator {
boolean supports(Class clazz);
void validate(Object target, Errors errors);
}
Spring API to validate
Add this to your bean configuration file. Replace the highlighted configuration files with your ones.
<bean id="validator" class="net.sf.oval.integration.spring.SpringValidator">
<constructor-arg>
<bean id="validator" class="net.sf.oval.Validator">
<constructor-arg>
<util:list>
<bean class="net.sf.oval.configuration.xml.XMLConfigurer">
<constructor-arg>
<value type="java.io.InputStream">classpath:com/test/validation/oval1-config.xml</value>
</constructor-arg>
</bean>
<bean class="net.sf.oval.configuration.xml.XMLConfigurer">
<constructor-arg>
<value type="java.io.InputStream">classpath:com/test/validation/oval2-config.xml</value>
</constructor-arg>
</bean>
</util:list>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
The class net.sf.oval.integration.spring.SpringValidator provides an implementation of Spring's org.springframework.validation.Validatorinterface and thus can be used for Spring Validation.
Wednesday, August 14, 2013
Resolve @Autowire from many candidates.
How to resolve @Autowire property from multiple instances?
or you got 'Spring finding multiple bean definition error' ?
Its simple.!
You need to use @Qualifier annotation here...!
public class MovieRecommender {
@Autowired
@Qualifier("main")
private MovieCatalog movieCatalog;
// ...
}
and your bean application context configuration will have this.
<context:annotation-config/>
<bean class="example.SimpleMovieCatalog">
<qualifier value="main"/>
<!-- inject any dependencies required by this bean -->
</bean>
<bean class="example.SimpleMovieCatalog">
<qualifier value="action"/>
<!-- inject any dependencies required by this bean -->
</bean>
Now you can switch between two qualifiers when ever you want too..! good luck.
or you got 'Spring finding multiple bean definition error' ?
Its simple.!
You need to use @Qualifier annotation here...!
public class MovieRecommender {
@Autowired
@Qualifier("main")
private MovieCatalog movieCatalog;
// ...
}
and your bean application context configuration will have this.
<context:annotation-config/>
<bean class="example.SimpleMovieCatalog">
<qualifier value="main"/>
<!-- inject any dependencies required by this bean -->
</bean>
<bean class="example.SimpleMovieCatalog">
<qualifier value="action"/>
<!-- inject any dependencies required by this bean -->
</bean>
Now you can switch between two qualifiers when ever you want too..! good luck.
Subscribe to:
Posts (Atom)
False fear
There is a figure they said She talks to me It's a mischievous voice I can't deny that love They say she is pretty Smart and wa...
-
Artist : Victor Rathnayaka [Intro] [ G - 4/4 ] ------------------------------------------------- | G | - | Em | - | | G...
-
The way I see it. If you are currently doing validation in a spring mvc application by implementing interface Validator undestanding spring...
-
This week I got a package from amazon and package tracker says USPS is delivering via priority mails. At the same time I find a key in my m...