Hello everyone, I deal with a small application on Spring MVC, the problem is as follows: when sending data to the database instead of Russian characters there is such an abracadabra

ÐÑекÑаÑна книга. 

I believe that the problem is in the encoding, but as it seems to me, it is configured correctly.

Application start object:

  @Configuration @ComponentScan(basePackages = {"controller","DAO","service"}) @EnableTransactionManagement public class WebConfig { @Bean public LocalSessionFactoryBean localSessionFactoryBean(){ LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean(); localSessionFactoryBean.setDataSource(dataSource()); localSessionFactoryBean.setPackagesToScan("entity"); localSessionFactoryBean.setHibernateProperties(hibernateProperties()); return localSessionFactoryBean; } @Bean public org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor postProcessor(){ return new org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor(); } @Autowired @Bean public HibernateTransactionManager platformTransactionManager(SessionFactory sessionFactory){ HibernateTransactionManager platformTransactionManager = new HibernateTransactionManager(); platformTransactionManager.setSessionFactory(sessionFactory); return platformTransactionManager; } @Bean public DataSource dataSource(){ DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("root"); dataSource.setPassword("root"); dataSource.setUrl("jdbc:mysql://localhost:3306/shop?useUnicode=yes&characterEncoding=UTF-8&useLegacyDatetimeCode=false&serverTimezone=UTC"); return dataSource; } private Properties hibernateProperties() { return new Properties() { { setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect"); put("hibernate.id.new_generator_mappings","false"); put("hbm2ddl.auto","update"); } }; } } 

Database Settings: [ [one]

What can be wrong, I use Freemarker, there it’s worth

 <meta charset="UTF-8"> 

Thank you in advance.

    1 answer 1

    In general, I solved the problem by adding a filter to the web.xml file. I hope someone will help.

      <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>