I wanted to make REST Api using Spring.
I have added Tomcat in Run/Debug Configurations.
Here is my Config class
#Configuration
#ComponentScan("com.dashkindima.blog.mvc")
#EnableWebMvc
#EnableTransactionManagement
public class MyConfig {
#Bean
public DataSource dataSource() {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/reeve?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&&characterEncoding=UTF8");
dataSource.setUser("root");
dataSource.setPassword("1234");
} catch (PropertyVetoException e) {
e.printStackTrace();
}
return dataSource;
}
#Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan("com.dashkindima.blog.mvc.hibernatetest.entity");
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
hibernateProperties.setProperty("hibernate.show_sql", "true");
sessionFactory.setHibernateProperties(hibernateProperties);
return sessionFactory;
}
#Bean
public HibernateTransactionManager transactionManager() {
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}
}
I have also defined WebInitializer class
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{MyConfig.class};
}
#Override
protected String[] getServletMappings() {
return new String[]{"/*"};
}
}
I have tried almost all urls in #RequestMapping like /api , /{app_name}/api but nothing happens.
#RestController
#RequestMapping("/blog/api")
public class MyRESTController {
#Autowired
private LivingComplexService livingComplexService;
#GetMapping("/living")
public List<LivingComplex> showAllLivingComplexes(){
List<LivingComplex> allComplexes = livingComplexService.getAllComplexes();
return allComplexes;
}
}
You can be sure that Service will return livingComplexes. So the problem is in Tomcat.
Related
I'm trying to retrieve data from application.properties file using Environment in my Spring Application but it's not working. I cant get the data bound correctly by Environment. I only can get this working if I use local variables as shown below:
AppConfig.class now!
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories("com.victommasi.eshop.dao")
#PropertySource("classpath:application.properties")
public class AppConfig {
private static final String driverClass = "com.mysql.jdbc.Driver";
private static final String url = "jdbc:mysql://localhost/eshop";
private static final String username = "root";
private static final String password = "root";
private static final String dialect = "org.hibernate.dialect.MySQL5Dialect";
private static final String showSql = "true";
private static final String formatSql = "true";
private static final String hbm2dllAuto = "update";
private static final String packageToScan = "com.victommasi.eshop.model";
#Bean
public DataSource dataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", dialect);
properties.put("hibernate.show_sql", showSql);
properties.put("hibernate.format_sql", formatSql);
properties.put("hibernate.hbm2ddl.auto", hbm2dllAuto);
return properties;
}
#Bean
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPersistenceProvider(new HibernatePersistenceProvider());
entityManagerFactoryBean.setPackagesToScan(packageToScan);
entityManagerFactoryBean.setJpaProperties(hibernateProperties());
return entityManagerFactoryBean;
}
}
AppConfig.class as I want
#Configuration
#EnableTransactionManagement
#EnableJpaRepositories("com.victommasi.eshop.dao")
#PropertySource("classpath:application.properties")
public class AppConfig {
#Autowired
private Environment env;
#Bean
public DataSource dataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClass"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.username"));
dataSource.setPassword(env.getProperty("jdbc.password"));
return dataSource;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
return properties;
}
#Bean
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
return transactionManager;
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPersistenceProvider(new HibernatePersistenceProvider());
entityManagerFactoryBean.setPackagesToScan(env.getProperty("packages.to.scan"));
entityManagerFactoryBean.setJpaProperties(hibernateProperties());
return entityManagerFactoryBean;
}
Other classes:
WebConfig.class
#EnableWebMvc
#Configuration
#ComponentScan(basePackages = { "com.victommasi.eshop" })
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
#Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
#Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setContentType("text/html;charset=UTF-8");
resolver.setSuffix(".jsp");
return resolver;
}
#Bean(name = "filterMultipartResolver")
public CommonsMultipartResolver getMultipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(1048576);
multipartResolver.setMaxInMemorySize(1048576);
return multipartResolver;
}
}
WebAppInitializer.class
public class WebAppInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(WebConfig.class, AppConfig.class, SecurityConfig.class);
container.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
dispatcherServlet.register(WebConfig.class);
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
I know it seems to be a very easy, I have also followed this tutorial, but cant get this done.
I didn't go through it all but it seems like you're missing the PropertySourcesPlaceholderConfigurer bean
Since Spring 3.1 introduced the new #PropertySource annotation, as a
convenient mechanism of adding property sources to the environment.
This annotation is to be used in conjunction with Java based
configuration and the #Configuration annotation:
#Configuration
#PropertySource("classpath:application.properties")
public class AppConfig {
#Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
With that, you can now start injecting a property with the #Value annotation is straightforward:
#Value( "${jdbc.url}" )
private String jdbcUrl;
On the other note, consider/look into spring-boot , you'll get all the above (including all the code you have shared)and much more out for free i.e with zero line of code
After reading a comment I took a look at console and found that data in 'application.properties' file were binded to AppConfig.class by Environment with blank spaces.
Stacktrace:
Caused by: java.sql.SQLException: Access denied for user 'root '#'localhost'
I assume it was the reason the binding wasn't working. My application is now working as I wanted. Thanks.
I am converting working hibernate project to Spring hibernate Project.In the existing project session factory creation has been done by loading hibernate cfg file.Since im going for spring i modified the session creation via Localsessionfactory by configuring in java.I am getting one strange exception as below
ORA-00942: table or view does not exist
But the same working fine in the hiberate cfg lookup.
I am using two transcation manager .Below is my code
Repository clas
#Repository
public class TestImpl implements
TestRepository {
#Autowired
#Qualifier("fSessionFactory")
SessionFactory sessionFactory;
#Autowired
#Qualifier("dSessionFactory")
SessionFactory sessionFactory2;
#SuppressWarnings("unchecked")
#Transactional("dTransaction")
public Recordse getOrders(String code, int id ) throws PersistenceException {
Session session = null;
try {
session =sessionFactory.getCurrentSession();
List<Order> orderList = session
.createQuery("FROM Orders WHERE CODE = :code AND NUM_CC = :id " )
.setParameter("code", code)
.setParameter("id", id)
.list();
}
catch (Exception e) {
throw new PersistenceException(e);
}
return empSickTime ;
}
#Transactional("fTransaction")
#Override
public SelectedRecords getRecords(String code, String grpId) throws PersistenceException {
Session session = null;
try {
session = sessionFactory2.getCurrentSession();
List<Records> recList = session
.createQuery("FROM Records WHERE CODE = :code AND GRP_CC = :id " )
.setParameter("code", code)
.setParameter("id", id)
.list();
}
}
catch (HibernateException e) {
throw new PersistenceException(e);
}
return qualifiedFleet;
}
}
PersistencConfig1
#Configuration
#EnableTransactionManagement
#PropertySource({ "classpath:persistence.properties" })
#ComponentScan({ "com.test.test2.*" })
public class PersistenceConfiguration1 {
#Autowired
private Environment env;
#Bean(name=" ")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(testDataSource());
sessionFactory.setPackagesToScan(new String[] {
" com.test.test2"});
sessionFactory.setHibernateProperties(hibernateProperties1());
return sessionFactory;
}
#Bean
public DataSource testDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.user"));
dataSource.setPassword(env.getProperty("jdbc.pass"));
return dataSource;
}
#Bean(name="dTransaction")
#Autowired
public HibernateTransactionManager transactionManager(
SessionFactory sessionFactory) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
#Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties hibernateProperties1() {
return new Properties() {
{
setProperty("hibernate.hbm2ddl.auto",
env.getProperty("hibernate.hbm2ddl.auto"));
setProperty("hibernate.dialect",
env.getProperty("hibernate.dialect"));
setProperty("hibernate.globally_quoted_identifiers", "true");
}
};
}
}
PersistenceConfig2
#Configuration
#EnableTransactionManagement
#PropertySource({ "classpath:persistence.properties" })
#ComponentScan({ "com.test.test3.*" })
public class PersistenceConfigurationDOTC {
#Autowired
private Environment env;
#Bean(name="dSessionFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(test1DataSource());
sessionFactory.setPackagesToScan(new String[] {
"com.test.test3.entity"});
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public DataSource test1DataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc1.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc1.url"));
dataSource.setUsername(env.getProperty("jdbc1.user"));
dataSource.setPassword(env.getProperty("jdbc1.pass"));
return dataSource;
}
#Bean(name = "fTransaction")
#Autowired
public HibernateTransactionManager transactionManager() {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactoryFCDS().getObject());
return txManager;
}
Properties hibernateProperties() {
return new Properties() {
{
setProperty("hibernate.hbm2ddl.auto",
env.getProperty("hibernate.hbm2ddl.auto"));
setProperty("hibernate.dialect",
env.getProperty("hibernate.dialect"));
setProperty("hibernate.globally_quoted_identifiers", "true");
}
};
}
}
Did I miss anything?
#Bean(name=" ")
public LocalSessionFactoryBean sessionFactory() {
It looks like your bean name is incorrect?
Another thing is in your fTransaction you are using session factory from your dSessionFactory as you declare sessionFactory2
#Autowired
#Qualifier("dSessionFactory")
SessionFactory sessionFactory2;
and then use in fTransaction
#Transactional("fTransaction")
#Override
public SelectedRecords getRecords(String code, String grpId) throws PersistenceException {
Session session = null;
try {
session = sessionFactory2.getCurrentSession();
I guess you are referring to the wrong DB connection.
Next time I would suggest giving your attributes more meaningful names, like paymentSessionFactory, geoSessionFactory & etc so that you won't mix var1 vs session2
I am using two different databases for my spring hibernate application.
I defined two persistence config file for creating two session factory.
When i start the servlet container it throws below exception
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'transactionManager' defined in class path resource
PersistenceConfig1
#Configuration
#EnableTransactionManagement
#PropertySource({ "classpath:persistence.properties" })
#ComponentScan({ "com.test.test2.*" })
public class PersistenceConfiguration1 {
#Autowired
private Environment env;
#Bean(name="fSessionFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(testDataSource());
sessionFactory.setPackagesToScan(new String[] {
" com.test.test2"});
sessionFactory.setHibernateProperties(hibernateProperties1());
return sessionFactory;
}
#Bean
public DataSource testDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.user"));
dataSource.setPassword(env.getProperty("jdbc.pass"));
return dataSource;
}
#Bean
#Autowired
public HibernateTransactionManager transactionManager(
SessionFactory sessionFactory) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
#Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties hibernateProperties1() {
return new Properties() {
{
setProperty("hibernate.hbm2ddl.auto",
env.getProperty("hibernate.hbm2ddl.auto"));
setProperty("hibernate.dialect",
env.getProperty("hibernate.dialect"));
setProperty("hibernate.globally_quoted_identifiers", "true");
}
};
}
}
Persistence Config 2
#Configuration
#EnableTransactionManagement
#PropertySource({ "classpath:persistence.properties" })
#ComponentScan({ "com.test.test3.*" })
public class PersistenceConfigurationDOTC {
#Autowired
private Environment env;
#Bean(name="dSessionFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(test1DataSource());
sessionFactory.setPackagesToScan(new String[] {
"com.test.test3.entity"});
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public DataSource test1DataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc1.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc1.url"));
dataSource.setUsername(env.getProperty("jdbc1.user"));
dataSource.setPassword(env.getProperty("jdbc1.pass"));
return dataSource;
}
Properties hibernateProperties() {
return new Properties() {
{
setProperty("hibernate.hbm2ddl.auto",
env.getProperty("hibernate.hbm2ddl.auto"));
setProperty("hibernate.dialect",
env.getProperty("hibernate.dialect"));
setProperty("hibernate.globally_quoted_identifiers", "true");
}
};
}
}
If I defined two transaction manager also im getting exception.
Help me on how to configure two transaction managers in one spring hibernate application.
Do you want a single transaction manager for both the configs? Or would you prefer a multiple config? Try defining transaction manager in your Persistence Config 2 too.
I am doing little project using Spring+Hibernate. When I deploy my war and get 404 status all the time. I have checked some answers about it, but I didnt find my mistake. I tried to switch between / and /*, it didnt help. Tomcat doesnt show any errors in logs. Thanks in advance.
My WebConfig class
#Configuration
#EnableWebMvc
#ComponentScan({"controller", "dao"})
#EnableTransactionManagement
public class WebConfig extends WebMvcConfigurerAdapter {
#Bean
public DataSource dataSource() {
SimpleDriverDataSource ds =
new SimpleDriverDataSource(org.h2.Driver.load(), "jdbc:h2:~/testdb", "sa", "sa");
return ds;
}
#Bean
#DependsOn("dataSource")
public LocalSessionFactoryBean sessionFactoryBean() {
LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource());
sessionFactoryBean.setPackagesToScan("entity");
sessionFactoryBean.setHibernateProperties(hibernateProperties());
return sessionFactoryBean;
}
private Properties hibernateProperties() {
Properties p = new Properties();
p.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
p.setProperty("hibernate.hbm2ddl.auto", "update");
p.setProperty("hibernate.hbm2ddl.import_files_sql_extractor", "org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor");
p.setProperty("hibernate.show_sql", "true");
p.setProperty("hibernate.format_sql", "true");
return p;
}
#Bean
#DependsOn("sessionFactoryBean")
public PlatformTransactionManager transactionManager() {
SessionFactory sessionFactory = sessionFactoryBean().getObject();
HibernateTransactionManager tm = new HibernateTransactionManager(sessionFactory);
return tm;
}
#Bean(name = "viewResolver")
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/pages/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
My WebAppInitializer class
public class SpringWebAppInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.register(WebConfig.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
"SpringDispatcher", new DispatcherServlet(appContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/*");
}
}
My Controller class
#Controller
public class MainController {
#Autowired
IDisksDao d;
#RequestMapping("/")
#Transactional
#ResponseBody
public String hello() {
return "hi";
}
#RequestMapping("disks/")
#Transactional
#ResponseBody
public ModelAndView getDisks() {
ModelAndView model = new ModelAndView("disks");
model.addObject("disks", d.getAllDisks() );
return model;
}
#RequestMapping("u/disks/{id}")
#Transactional
#ResponseBody
public List<Disk> getUserDisks(#PathVariable int id) {
return d.getAllUserDisks(id);
}
}
My project structure
I am using hibernate-validator 5.1.2.Final and Spring 4.0.6.RELEASE and want to make use of fail-fast so that when I have configured an annotation with multiple constraints, they are not all executed and only the first error message is returned.
#MultipartFileNotEmpty
#CsvFile
#Documented
#Constraint(validatedBy = { })
#Target(ElementType.FIELD)
#Retention(RetentionPolicy.RUNTIME)
public #interface OrderCsv {
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
From looking at the Hibernate Validator docs it appears I can enable fail_fast at a global level, but I am unsure how to enable this within Java config. My current hibernate configuration looks like:
#Configuration
#EnableTransactionManagement
#ComponentScan(basePackages="uk.co.project")
public class HibernateConfig {
final static String JDBC_URL = "jdbc:mysql://localhost:3306/";
final static String DRIVER_CLASS = "com.mysql.jdbc.Driver";
#Autowired
private Environment environment;
#Bean
public DataSource dataSource() {
BasicDataSource dataSource = new org.apache.commons.dbcp2.BasicDataSource();
dataSource.setDriverClassName(DRIVER_CLASS);
dataSource.setUsername(environment.getProperty("datasource.username"));
dataSource.setPassword(environment.getProperty("datasource.password"));
dataSource.setUrl(JDBC_URL + environment.getProperty("datasource.database"));
dataSource.setInitialSize(10);
return dataSource;
}
#Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "uk.co.project.models" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public HibernateTransactionManager transactionManager() {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory().getObject());
return txManager;
}
#Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties hibernateProperties() {
return new Properties() {
private static final long serialVersionUID = 1L;
{
setProperty("hibernate.hbm2ddl.auto", "validate");
setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
setProperty("hibernate.globally_quoted_identifiers", "true");
setProperty("hibernate.show_sql", "true");
}
};
}
}
I have tried adding setProperty("hibernate.validator.fail_fast", "true"); to my hibernateProperties but that did not work. I would appreciate any pointers on how to enable fail_fast within my hibernate java config.
"hibernate.validator.fail_fast" property is not the property of sessionFactory it is property for ValidatorFactory, you can try something like this:
#Bean
public LocalValidatorFactoryBean getValidatorFactory() {
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.getValidationPropertyMap().put("hibernate.validator.fail_fast", "true");
return localValidatorFactoryBean;
}