Java
13
Вклад в тег
@PersistenceContext(unitName = Constants.ADM_ENTITY_MANAGER_FACTORY_NAME)
private EntityManager em;
@Bean(name = Constants.ADM_ENTITY_MANAGER_FACTORY_NAME, destroyMethod = "")
public LocalContainerEntityManagerFactoryBean admEntityManagerFactory() throws NamingException {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSourceAdm());
em.setPackagesToScan(admPackagesToScan);
em.setPersistenceUnitName(Constants.ADM_ENTITY_MANAGER_FACTORY_NAME);
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(hibernatePropertiesAdm());
return em;
}
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(SpringConfig.class, WebConfig.class);
context.setServletContext(servletContext);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
FilterRegistration.Dynamic filterRegistration = servletContext
.addFilter("characterEncodingFilter", characterEncodingFilter);
filterRegistration.addMappingForUrlPatterns(null, false, "/*");
}
}
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
FilterRegistration.Dynamic filterRegistration = servletContext
.addFilter("characterEncodingFilter", characterEncodingFilter);
filterRegistration.addMappingForUrlPatterns(null, false, "/*");