2015-12-11 6 views
1

У меня есть функциональное приложение Spring Boot Web.Начало Весенней загрузки Война в экземпляре tomcat

Когда я начинаю его из моего Eclipse, все нормально (см @SpringBootApplication ниже)

Но когда я пытаюсь загрузить сгенерированный WAR с котом 7, я получаю следующие ошибки в Catalina лог-файл

GRAVE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/schdtool-war-1.0-SNAPSHOT]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649) 
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081) 
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private fr.myapp.schdtool.service.interfaces.ISettingService fr.myapp.schdtool.controller.AuthController.settingService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private fr.myapp.schdtool.persistence.dao.interfaces.ISettingDAO fr.myapp.schdtool.service.SettingService.settingDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected javax.persistence.EntityManager fr.myapp.schdtool.persistence.dao.AbstractDAO.entityManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) 
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) 
    at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149) 
    at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129) 
    at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85) 
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5481) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    ... 10 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private fr.myapp.schdtool.service.interfaces.ISettingService fr.myapp.schdtool.controller.AuthController.settingService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private fr.myapp.schdtool.persistence.dao.interfaces.ISettingDAO fr.myapp.schdtool.service.SettingService.settingDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected javax.persistence.EntityManager fr.myapp.schdtool.persistence.dao.AbstractDAO.entityManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 
    ... 30 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private fr.myapp.schdtool.persistence.dao.interfaces.ISettingDAO fr.myapp.schdtool.service.SettingService.settingDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected javax.persistence.EntityManager fr.myapp.schdtool.persistence.dao.AbstractDAO.entityManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) 
    ... 32 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private fr.myapp.schdtool.persistence.dao.interfaces.ISettingDAO fr.myapp.schdtool.service.SettingService.settingDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected javax.persistence.EntityManager fr.myapp.schdtool.persistence.dao.AbstractDAO.entityManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 
    ... 43 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settingDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected javax.persistence.EntityManager fr.myapp.schdtool.persistence.dao.AbstractDAO.entityManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) 
    ... 45 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected javax.persistence.EntityManager fr.myapp.schdtool.persistence.dao.AbstractDAO.entityManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 
    ... 56 more 
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1126) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) 
    ... 58 more 

кажется, что веб-приложение начинает штраф один раз (видел в TOMCAT консоли), а затем перезапустить и не может завершить запуск (???), но нет никаких следов этого первого запуска в журналах Catalina

@SpringBootApplication 
public class SchdtoolApplication extends SpringBootServletInitializer { 

    public static void main(String[] args) { 
     SpringApplication.run(SchdtoolApplication.class, args); 
    } 
} 


@Configuration 
@EnableWebMvc 
@EnableTransactionManagement 
@ComponentScan("fr.myapp") 
public class WebAppConfig extends WebMvcConfigurerAdapter { 

    @Bean 
    public DataSource dataSource() { 
      SimpleDriverDataSource d = new SimpleDriverDataSource(); 
      d.setConnectionProperties(dProperties()); 
      d.setDriverClass(Driver.class); 
      d.setUrl("jdbc:postgresql://localhost:5432/mydb"); 
      d.setUsername("BNF0016779"); 
      d.setPassword(""); 
      return d; 
    } 

    @Bean 
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 
      LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); 
      entityManagerFactoryBean.setDataSource(dataSource()); 
      entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); 
      entityManagerFactoryBean.setPackagesToScan("fr.myapp"); 

      entityManagerFactoryBean.setJpaProperties(hibProperties()); 

      return entityManagerFactoryBean; 
    } 

    private Properties hibProperties() { 
      Properties properties = new Properties(); 
      properties.put("hibernate.hbm2ddl.auto", "update"); 
      properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); 
      properties.put("hibernate.show_sql", "false"); 
      return properties;   
    } 

    private Properties dProperties() { 
     Properties properties = new Properties(); 
     properties.put("spring.jpa.database", "POSTGRESQL"); 
     return properties;   
} 

    @Autowired 
    private ApplicationContext applicationContext; 

    @Bean 
    public SchedulerFactoryBean configureScheduler() { 
     SchedulerFactoryBean f = new SchedulerFactoryBean(); 
     f.setDataSource(dataSource()); 
     f.setJobFactory(new SpringBeanJobFactory()); 
     f.setAutoStartup(false); 
     Properties properties = new Properties(); 
     properties.setProperty("org.quartz.threadPool.threadCount", "3"); 
     properties.setProperty("org.quartz.jobStore.useProperties", "false"); 
     properties.setProperty("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate"); 
     f.setQuartzProperties(properties); 
     f.setApplicationContext(applicationContext); 
     f.setApplicationContextSchedulerContextKey("applicationContext"); 
     return f; 
    } 
} 

Я также получаю эту ошибку, может ли это быть вовлечено?

tomcat-embed-el-8.0.28.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class 

ответ

0

Итак, ваша проблема

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] is defined: expected single matching bean but found 3: org.springframework.orm.jpa.SharedEntityManagerCreator#0,org.springframework.orm.jpa.SharedEntityManagerCreator#1,org.springframework.orm.jpa.SharedEntityManagerCreator#2 

Эта проблема возникает, когда у вас есть несколько EntityManager.

@Bean(name = "your-entity-manager-factory") 
@Primary 
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 
Смежные вопросы