Spring Boot-创建名称为'jmsConnectionFactory'的bean时出错

马克斯·加布达拉赫马诺夫

Spring Boot的新功能。我正在尝试在Tomcat(8.0.30)服务器上运行Spring Boot应用程序。这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.pr.hotels</groupId>
        <artifactId>hotels</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>api-consumer</artifactId>
    <packaging>war</packaging>
    <name>api-consumer</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.0.4.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>

        <dependency>
            <groupId>com.pr</groupId>
            <artifactId>amqp</artifactId>
            <version>2.1.3-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>

            </exclusions>
        </dependency>

    </dependencies>

    <build>
        <finalName>booking</finalName>
        <plugins>
            <plugin>
                <!-- Add Maven coordinates (GAV) for: maven-war-plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

这是配置类:

    @Configuration
    @EnableTransactionManagement
    @ComponentScan("com.pr.hotels.apiconsumer")
    @EnableJpaRepositories("com.pr.hotels.apiconsumer")
    @PropertySource("classpath:application.properties")
    public class DataConfig
    {

        private static final String PROP_DATABASE_JDBC_URL = "jdbc.url";
        private static final String PROP_HIBERNATE_DIALECT = "db.hibernate.dialect";
        private static final String PROP_HIBERNATE_SHOW_SQL = "db.hibernate.show_sql";
        private static final String PROP_ENTITYMANAGER_PACKAGES_TO_SCAN = "db.entitymanager.packages.to.scan";
        private static final String PROP_HIBERNATE_HBM2DDL_AUTO = "db.hibernate.hbm2ddl.auto";
        private static final String PROP_LOB = "hibernate.jdbc.lob.non_contextual_creation";

        @Resource
        private Environment env;

        @Bean
        public DataSource dataSource() throws NamingException
        {
            Context init = new InitialContext();
            Context env = (Context) init.lookup("java:/comp/env/");
            DataSource data = (DataSource) env.lookup("jdbc/hotels");

            return data;
        }

        @Bean
        public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws NamingException
        {
            LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
            entityManagerFactoryBean.setDataSource(dataSource());
            entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
            entityManagerFactoryBean.setPackagesToScan(env.getRequiredProperty(PROP_ENTITYMANAGER_PACKAGES_TO_SCAN));
            entityManagerFactoryBean.setJpaProperties(getHibernateProperties());

            return entityManagerFactoryBean;
        }

        @Bean
        public JpaTransactionManager transactionManager() throws NamingException
        {
            JpaTransactionManager transactionManager = new JpaTransactionManager();
            transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());

            return transactionManager;
        }

        private Properties getHibernateProperties()
        {
            Properties properties = new Properties();
            properties.put(PROP_HIBERNATE_DIALECT, env.getRequiredProperty(PROP_HIBERNATE_DIALECT));
            properties.put(PROP_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROP_HIBERNATE_SHOW_SQL));
            properties.put(PROP_HIBERNATE_HBM2DDL_AUTO, env.getRequiredProperty(PROP_HIBERNATE_HBM2DDL_AUTO));
            properties.put(PROP_LOB, env.getRequiredProperty(PROP_LOB));

            return properties;
        }

    }

每次与关联的错误时ActiveMQ,但与ActiveMQ没有任何显式依赖关系(可能是我错了)。这是错误:

 2018-09-07 14:52:50.312  WARN 5504 --- [localhost-startStop-4] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-09-07 14:52:50.890  WARN 5504 --- [localhost-startStop-4] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.activemq.ActiveMQConnectionFactory]: Factory method 'jmsConnectionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.activemq.ActiveMQConnectionFactory.setNonBlockingRedelivery(Z)V
2018-09-07 14:52:50.890  INFO 5504 --- [localhost-startStop-4] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-09-07 14:52:50.906  INFO 5504 --- [localhost-startStop-4] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-07 14:52:50.906 ERROR 5504 --- [localhost-startStop-4] o.s.b.SpringApplication                  : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.activemq.ActiveMQConnectionFactory]: Factory method 'jmsConnectionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.activemq.ActiveMQConnectionFactory.setNonBlockingRedelivery(Z)V
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172) [spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [catalina.jar:8.5.24]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.5.24]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752) [catalina.jar:8.5.24]
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728) [catalina.jar:8.5.24]
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) [catalina.jar:8.5.24]
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986) [catalina.jar:8.5.24]
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857) [catalina.jar:8.5.24]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_161]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.activemq.ActiveMQConnectionFactory]: Factory method 'jmsConnectionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.activemq.ActiveMQConnectionFactory.setNonBlockingRedelivery(Z)V
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    ... 31 more
Caused by: java.lang.NoSuchMethodError: org.apache.activemq.ActiveMQConnectionFactory.setNonBlockingRedelivery(Z)V
    at org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionFactoryFactory.doCreateConnectionFactory(ActiveMQConnectionFactoryFactory.java:72) ~[spring-boot-autoconfigure-2.0.4.RELEASE.jar:2.0.4.RELEASE]

我究竟做错了什么?

马克斯·加布达拉赫马诺夫

最后,我在这里找到了答案https://stackoverflow.com/a/41326790/1912193需要ActiveMQAutoConfiguration从Spring Boot中排除

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot错误:创建名称为“ entityManagerFactory”的bean时出错

具有Spring Security的Spring Boot:创建名称为“ securityFilterChainRegistration”的bean时出错

Spring Boot-在类路径资源中创建名称为'dataSource'的bean时出错

创建名称为'roleRepository'的Java Spring Boot时出错

Spring Boot错误创建名称为'optionalLiveReloadServer'的bean

由于创建名称为adminHandlerMapping的bean时出错,Spring-Boot-Admin应用程序无法启动

创建名称为'requestMappingHandlerAdapter'的Spring Boot时出错

为什么在尝试在Spring Boot应用程序上配置数据库连接时出现此异常?创建名称为“ dataSource”的bean时出错

需要帮忙!Spring Boot错误:不满意的DependancyException:创建名称为''的bean时出错

运行spring boot build:在类路径中创建名称为'entityManagerFactory'的bean时出错

Spring Boot Test-创建名称为SpringBootRepositoryRestMvcConfiguration的bean时出错

在TomEE上部署Spring Boot应用程序时出错:UnsatisfiedDependencyException:创建名称为'employeeController'的bean时出错

使用Spring Boot时在类路径资源中定义名称为'entityManagerFactory'的bean创建时出错

在Spring Boot的JUnit测试中创建bean时出错

Spring Boot异常,创建bean时出错

在Spring Boot中创建在类路径资源中定义的名称为'redisson'的bean时出错

在Spring Boot中创建名称为'batchConfigurer'的bean时出错

Spring Boot 2.1.1到2.1.2:创建名称为'payloadRootAnnotationMethodEndpointMapping'的bean时出错

在Spring Boot App中创建名称为'liquibase'的bean时出错

在spring-boot中使用kotlin暂停功能创建名称为'requestMappingHandlerMapping'的bean时出错

在JBoss EAP 7.1.0中部署Spring Boot应用程序时,创建名称为“ undertowServletWebServerFactory”的bean时出错

在Weblogic BeanCreationException中部署Spring Batch时出错:创建名称为'jobRepository'的bean时出错

Spring-boot和spring-data-jpa Mysql:创建名称为'entityManagerFactory'的bean时出错

Spring Boot:+ Spring Data Rest:在类路径资源中定义名称为“entityManagerFactory”的 bean 创建时出错

Spring boot:创建名为“methodValidationPostProcessor”的bean时出错

导致原因:org.springframework.beans.factory.BeanCreationException:使用 Spring Boot 2 创建名称为错误的 bean 时出错

在 Spring Boot 中创建名为 DataSourceTransactionManager 的 bean 时出错 [JPA]

Kotlin Spring Boot Gradle - 创建名称为“resourceHandlerMapping”的 bean 时出错 - 未设置 ServletContext

创建文件 Spring Boot 中定义的名称为“postsController”的 bean 时出错