Помощь !! Все ответы, которые я нашел: изменить версию javax.servlet-api на 3.0.1 изменить на org.mortbay.jetty: servlet-api: 3.0.20100224 изменить область действия при условии, изменить версию весны на 5.1.6.RELEASE, openJDK 11 нет Работа. Запуск: mvn tomcat7: запустить Очистить и установить проект не было ошибок.
Настройка AppInit из документов Spring:
public class AppInit implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext =
new AnnotationConfigWebApplicationContext();
rootContext.register(WebConfig.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext =
new AnnotationConfigWebApplicationContext();
dispatcherContext.register(AppInit.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher =
container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}}
WebConf:
@Configuration
@EnableWebMvc
@ComponentScan
@EnableTransactionManagement
@PropertySource("classpath:database.properties")
@PropertySource("classpath:hibernate.properties")
public class WebConfig implements WebMvcConfigurer {
@Autowired
private Environment env;
@Autowired
private ApplicationContext applicationContext;
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
registry.viewResolver(resolver);
}
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(applicationContext);
templateResolver.setCacheable(true);
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix("/WEB-INF/views/");
templateResolver.setSuffix(".html");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
@Bean
public BasicDataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(env.getProperty("connection.url"));
dataSource.setUsername(env.getProperty("connection.username"));
dataSource.setPassword(env.getProperty("connection.password"));
dataSource.setDriverClassName(env.getProperty("connection.driver_class"));
dataSource.setMaxTotal(Integer.parseInt(env.getProperty("connection.max_total")));
return dataSource;
}
@Bean
public LocalSessionFactoryBean localSessionFactoryBean(DataSource dataSource) {
LocalSessionFactoryBean localSessionFactoryBean
= new LocalSessionFactoryBean();
localSessionFactoryBean.setDataSource(dataSource);
localSessionFactoryBean.setHibernateProperties(hibernateProperties());
localSessionFactoryBean.setAnnotatedPackages("by/entity");
localSessionFactoryBean.setPackagesToScan("by/entity");
return localSessionFactoryBean;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
return properties;
}
@Bean
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory);
return transactionManager;
}}
Stacktrace:
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/booking]]
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/booking]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.ClassCastException: class by.AppInit cannot be cast to class javax.servlet.ServletContainerInitializer (by.AppInit is in unnamed module of loader org.apache.catalina.loader.WebappClassLoader @139bdc32; javax.servlet.ServletContainerInitializer is in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @64a8d575)
at org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1670)
at org.apache.catalina.startup.ContextConfig.getServletContainerInitializers(ContextConfig.java:1652)
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1562)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Заранее спасибо!