4

我的问题与这个问题非常相似,而且有点简单:从 maven 复制粘贴服务到 gradle 项目使启动器无法运行。

是我用作示例的项目,它开始时就像一个魅力:

Spring-Boot:  (v2.2.5.RELEASE)
Camunda BPM: (v7.12.0)
Camunda BPM Spring Boot Starter: (v3.4.1)

INFO 227460 --- [main] com.camunda.demo.springboot.Application  : Starting Application on archbox with PID 227460 (/home/user/ide/IdeaProjects/camunda-spring-boot-amqp-microservice-cloud-example/target/classes started by user in /home/user/ide/IdeaProjects/camunda-spring-boot-amqp-microservice-cloud-example)
INFO 227460 --- [main] com.camunda.demo.springboot.Application  : No active profile set, falling back to default profiles: default
INFO 227460 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
INFO 227460 --- [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
INFO 227460 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
INFO 227460 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
INFO 227460 --- [main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1095 ms
INFO 227460 --- [main] .c.b.s.b.s.r.CamundaJerseyResourceConfig : Configuring camunda rest api.
INFO 227460 --- [main] .c.b.s.b.s.r.CamundaJerseyResourceConfig : Finished configuring camunda rest api.
INFO 227460 --- [main] org.camunda.bpm.spring.boot              : STARTER-SB040 Setting up jobExecutor with corePoolSize=3, maxPoolSize:10
INFO 227460 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'camundaTaskExecutor'
INFO 227460 --- [main] org.camunda.bpm.engine.cfg               : ENGINE-12003 Plugin 'CompositeProcessEnginePlugin[genericPropertiesConfiguration, camundaEngineHistoryConfiguration, camundaIdGeneratorConfiguration, camundaProcessEngineConfiguration, camundaDatasourceConfiguration, camundaJobConfiguration, camundaHistoryConfiguration, camundaMetricsConfiguration, camundaAuthorizationConfiguration, failedJobConfiguration, SendEventListenerPlugin, disableDeploymentResourcePattern, eventPublisherPlugin]' activated on process engine 'default'
INFO 227460 --- [main] org.camunda.bpm.spring.boot              : STARTER-SB020 ProcessApplication enabled: autoDeployment via springConfiguration#deploymentResourcePattern is disabled
INFO 227460 --- [main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-001: Initialized Camunda Spring Boot Eventing Engine Plugin.
INFO 227460 --- [main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-003: Task events will be published as Spring Events.
INFO 227460 --- [main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-005: Execution events will be published as Spring Events.
INFO 227460 --- [main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-007: History events will be published as Spring events.
INFO 227460 --- [main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
INFO 227460 --- [main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
INFO 227460 --- [main] org.camunda.bpm.engine                   : ENGINE-00001 Process Engine default created.
INFO 227460 --- [main] o.c.b.s.b.s.w.f.LazyInitRegistration     : lazy initialized org.camunda.bpm.spring.boot.starter.webapp.filter.LazyProcessEnginesFilter@69364b2d
INFO 227460 --- [main] o.c.b.s.b.s.w.f.LazyInitRegistration     : lazy initialized org.camunda.bpm.spring.boot.starter.webapp.filter.LazySecurityFilter@52f6900a

但是我从部分来源复制的项目给出了以下内容:

Spring-Boot:  (v2.1.3.RELEASE)
Camunda BPM: (v7.12.0)
Camunda BPM Spring Boot Starter: (v3.4.1)

 INFO 227891 --- [main] com.test.camundatest.Application         : Starting Application on archbox with PID 227891 (/home/user/ide/IdeaProjects/gradle-camunda-service/build/classes/java/main started by user in /home/user/ide/IdeaProjects/gradle-camunda-service)
 INFO 227891 --- [main] com.test.camundatest.Application         : No active profile set, falling back to default profiles: default
 INFO 227891 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
 INFO 227891 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
 INFO 227891 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 repository interfaces.
 INFO 227891 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
 INFO 227891 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
 INFO 227891 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 3ms. Found 0 repository interfaces.
 INFO 227891 --- [main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$d980ca4f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
 INFO 227891 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
 INFO 227891 --- [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
 INFO 227891 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]
 INFO 227891 --- [main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
 INFO 227891 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
 INFO 227891 --- [main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1883 ms
ERROR 227891 --- [main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.camunda.bpm.engine.spring.SpringProcessEngineServicesConfiguration': Unsatisfied dependency expressed through field 'processEngine'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.camunda.bpm.spring.boot.starter.CamundaBpmAutoConfiguration$ProcessEngineConfigurationImplDependingConfiguration': Unsatisfied dependency expressed through field 'processEngineConfigurationImpl'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 INFO 227891 --- [main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
 WARN 227891 --- [main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
 INFO 227891 --- [main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-06 10:21:45.754 ERROR 227891 --- [main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field processEngineConfigurationImpl in org.camunda.bpm.spring.boot.starter.CamundaBpmAutoConfiguration$ProcessEngineConfigurationImplDependingConfiguration required a bean of type 'org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl' that could not be found.

The following candidates were found but could not be injected:
- Bean method 'processEngineConfigurationImpl' in 'CamundaBpmConfiguration' not loaded because @ConditionalOnMissingBean (types: org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; SearchStrategy: all) found beans of type 'org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl' processEngineConfiguration


Action:

Consider revisiting the entries above or defining a bean of type 'org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl' in your configuration.

我应该在配置中添加/更改什么以使我的“gradle”服务像“maven”一样工作?

4

1 回答 1

2

令人惊讶的是,两个给定项目检索连接和数据源详细信息的方式存在关键差异。

例如,我将其放入 maven 项目属性中以将 camunda 引擎指向我的数据库就足够了(“按原样”保留):

spring.datasource.url=${POSTGRES_ADDRESS:jdbc:postgresql://localhost:5432/myservice}
spring.datasource.username=${POSTGRES_USER:postgres}
spring.datasource.password=${POSTGRES_PASSWORD:12345}
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

虽然相同的配置完全不适用于 gradle,processEngineConfigurationImpl但当引擎需要的只是数据库连接详细信息时,会隐晦地抱怨 bean 缺失。

所以这就是我的想法:

@Configuration
@ImportResource({"classpath:config.xml"})
public class Config {

    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;

    @Bean
    public DataSource dataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("org.postgresql.Driver");
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new DataSourceTransactionManager(dataSource());
    }

    @Bean
    public ProcessEngineConfigurationImpl processEngineConfiguration() throws IOException {
        SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
        config.setDataSource(dataSource());
        config.setTransactionManager(transactionManager());
        config.setDatabaseSchemaUpdate("true");
        config.setJobExecutorActivate(true);
        config.setAuthorizationEnabled(true);
        config.setDefaultSerializationFormat("application/json");
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        config.setDeploymentResources(resolver.getResources("classpath:/bpmn/*.bpmn"));
        List<ProcessEnginePlugin> processEnginePlugins = new ArrayList<>();
        config.setProcessEnginePlugins(processEnginePlugins);
        return config;
    }
}

它有效:

  Spring-Boot:  (v2.1.3.RELEASE)
  Camunda BPM: (v7.13.0)
  Camunda BPM Spring Boot Starter: (v7.13.0)

INFO 378753 --- [main] com.myname.myservice.Application   : Starting Application on pc with PID 378753 (/home/user/IdeaProjects/myservice/build/classes/java/main started by user in /home/user/IdeaProjects/myservice)
INFO 378753 --- [main] com.myname.myservice.Application   : No active profile set, falling back to default profiles: default
INFO 378753 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
INFO 378753 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
INFO 378753 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7ms. Found 0 repository interfaces.
INFO 378753 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
INFO 378753 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
INFO 378753 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7ms. Found 0 repository interfaces.
INFO 378753 --- [main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.kafka.annotation.KafkaBootstrapConfiguration' of type [org.springframework.kafka.annotation.KafkaBootstrapConfiguration$$EnhancerBySpringCGLIB$$f04798b1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO 378753 --- [main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$1c95872e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO 378753 --- [main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 5.2.4 by Boxfuse
INFO 378753 --- [main] o.f.c.internal.database.DatabaseFactory  : Database: jdbc:postgresql://localhost:5432/myservice (PostgreSQL 12.1)
WARN 378753 --- [main] o.f.c.internal.database.base.Database    : Flyway upgrade recommended: PostgreSQL 12.1 is newer than this version of Flyway and support has not been tested.
INFO 378753 --- [main] o.f.core.internal.command.DbValidate     : Successfully validated 2 migrations (execution time 00:00.010s)
INFO 378753 --- [main] o.f.core.internal.command.DbMigrate      : Current version of schema "public": 1
INFO 378753 --- [main] o.f.core.internal.command.DbMigrate      : Schema "public" is up to date. No migration necessary.
INFO 378753 --- [main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
INFO 378753 --- [main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.7.Final}
INFO 378753 --- [main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
INFO 378753 --- [main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
INFO 378753 --- [main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL95Dialect
INFO 378753 --- [main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000422: Disabling contextual LOB creation as connection was null
INFO 378753 --- [main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@642c6461
INFO 378753 --- [main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
INFO 378753 --- [main] org.camunda.feel.FeelEngine              : Engine created. [value-mapper: CompositeValueMapper(List(org.camunda.feel.impl.JavaValueMapper@a047bdb)), function-provider: org.camunda.bpm.dmn.feel.impl.scala.function.CustomFunctionTransformer@173b1af1, configuration: Configuration(false)]
INFO 378753 --- [main] org.camunda.bpm.engine                   : ENGINE-00001 Process Engine default created.
INFO 378753 --- [main] org.camunda.bpm.engine.jobexecutor       : ENGINE-14014 Starting up the JobExecutor[org.camunda.bpm.engine.impl.jobexecutor.DefaultJobExecutor].
INFO 378753 --- [ultJobExecutor]] org.camunda.bpm.engine.jobexecutor       : ENGINE-14018 JobExecutor[org.camunda.bpm.engine.impl.jobexecutor.DefaultJobExecutor] starting to acquire jobs
INFO 378753 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'asyncExecutor'
INFO 378753 --- [main] i.micrometer.influx.InfluxMeterRegistry  : publishing metrics to influx every 1m
INFO 378753 --- [main] org.camunda.bpm.spring.boot              : STARTER-SB040 Setting up jobExecutor with corePoolSize=3, maxPoolSize:10
INFO 378753 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'camundaTaskExecutor'
INFO 378753 --- [main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
INFO 378753 --- [main] n.d.b.g.s.s.GrpcServerLifecycle          : gRPC Server started, listening on address: *, port: 8081
INFO 378753 --- [main] org.camunda.bpm.container                : ENGINE-08024 Found processes.xml file at file:/home/user/IdeaProjects/myservice/build/resources/main/META-INF/processes.xml
INFO 378753 --- [main] org.camunda.bpm.container                : ENGINE-08023 Deployment summary for process archive 'application': 

作为旁注-由于未知原因,sql方言对于bpm非常重要,因此必须像这样设置:

spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL95Dialect

如果使用,不要忘记请flyway:

spring.flyway.baseline-on-migrate = true
于 2020-06-07T13:27:03.003 回答