后端开发启动demo报错

  • Choerodon平台版本:0.6.0

  • 运行环境(如localhost或k8s):localhost

  • 遇到问题时的前置条件:

  • 问题描述:
    Choerodon后端小白一只,只是想先搭一个SpringBoot的demo先跑起来。克隆了新建的项目,先把有关的插件先注释了,但是启动还是报错
    先在pom文件里修改了版本,进行了重新构建
    image
    然后在application里面注释掉了插件有关的
    # application.yml
    spring:
    # sleuth:
    # integration:
    # enabled: false
    # scheduled:
    # enabled: false
    # sampler:
    # percentage: 1.0
    # stream:
    # enabled: true
    datasource:
    url: jdbc:mysql://localhost:3306/demo_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: root
    # kafka: #使用原生spring kafka需要配置
    # bootstrap-servers: localhost:9092
    # consumer:
    # group-id: iam-service
    # auto-offset-reset: earliest
    # cloud:
    # bus:
    # enabled: true
    # stream:
    # kafka:
    # binder:
    # brokers: 127.0.0.1:9092
    # zkNodes: 127.0.0.1:2181
    #event:
    # store:
    # service:
    # name: event-store-service
    #choerodon:
    # ldap:
    # userNameType: 0
    # devops:
    # message: true
    # event:
    # consumer:
    # enabled: true # 是否开启,不设置默认开启
    # queue-type: kafka # 消息队列类型,目前仅支持kafka
    # enable-duplicate-remove: true # 是否开启去重功能
    # failed-strategy: nothing # 消息失败策略
    # retry:
    # enabled: true # 是否开启重试功能
    # kafka:
    # bootstrap-servers: localhost:9092
    eureka:
    instance:
    preferIpAddress: true
    leaseRenewalIntervalInSeconds: 10
    leaseExpirationDurationInSeconds: 30
    metadata-map:
    VERSION: v1
    client:
    serviceUrl:
    defaultZone: http://localhost:8000/eureka/
    registryFetchIntervalSeconds: 10
    #hystrix:
    # command:
    # default:
    # execution:
    # isolation:
    # thread:
    # timeoutInMilliseconds: 15000
    # stream:
    # queue:
    # enabled: false
    #ribbon:
    # ReadTimeout: 5000
    # ConnectTimeout: 5000
    #file-service:
    # ribbon:
    # ReadTimeout: 15000
    # ConnectTimeout: 15000
    mybatis:
    mapperLocations: classpath*:/mapper/*.xml
    configuration: # 数据库下划线转驼峰配置
    mapUnderscoreToCamelCase: true
    在values.yaml中注释了kafka相关的
    # Default values for manager-service.
    # This is a YAML-formatted file.
    # Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: registry.cn-hangzhou.aliyuncs.com/ora-xadc/xa-todo-servie
pullPolicy: Always

preJob:
preConfig:
configFile: application.yml
mysql:
host: 192.168.12.175
port: 3306
database: manager_service
username: root
password: choerodon
preInitDB:
mysql:
host: 192.168.12.175
port: 3306
database: demo_service
username: root
password: choerodon

deployment:
managementPort: 18088

env:
open:
## register-server
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://register-server.io-choerodon:8000/eureka/
## config-server
SPRING_CLOUD_CONFIG_ENABLED: true
SPRING_CLOUD_CONFIG_URI: http://config-server.framework:8010/
## mysql
SPRING_DATASOURCE_URL: jdbc:mysql://localhost/demo_service?useUnicode=true&characterEncoding=utf-8&useSSL=false
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: choerodon
## kafka
# CHOERODON_EVENT_CONSUMER_KAFKA_BOOTSTRAP_SERVERS: kafka-0.kafka-headless.kafka.svc.cluster.local:9092,kafka-1.kafka-headless.kafka.svc.cluster.local:9092,kafka-2.kafka-headless.kafka.svc.cluster.local:9092
# SPRING_CLOUD_STREAM_KAFKA_BINDER_BROKERS: kafka-0.kafka-headless.kafka.svc.cluster.local:9092,kafka-1.kafka-headless.kafka.svc.cluster.local:9092,kafka-2.kafka-headless.kafka.svc.cluster.local:9092
# SPRING_CLOUD_STREAM_KAFKA_BINDER_ZK_NODES: zookeeper-0.zookeeper-headless.zookeeper.svc.cluster.local:2181,zookeeper-1.zookeeper-headless.zookeeper.svc.cluster.local:2181,zookeeper-2.zookeeper-headless.zookeeper.svc.cluster.local:2181
# SPRING_KAFKA_PRODUCER_VALUE_SERIALIZER: org.apache.kafka.common.serialization.ByteArraySerializer

metrics:
path: /prometheus
group: spring-boot

logs:
parser: spring-boot

persistence:
enabled: false
## A manually managed Persistent Volume and Claim
## Requires persistence.enabled: true
## If defined, PVC must be created manually before volume will be bound
# existingClaim:
# subPath:

service:
enabled: false
type: ClusterIP
port: 18080

ingress:
enabled: false

resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources,such as Minikube. If you do want to specify resources,uncomment the following
# lines,adjust them as necessary,and remove the curly braces after ‘resources:’.
limits:
# cpu: 100m
memory: 2Gi
requests:
# cpu: 100m
memory: 1.5Gi
由于在跑的时候有提示18081端口已被占用,所以我改成18088了
注释了demo类中的引用


报了zookeeper连接异常的错误
2018-08-28 22:49:20.573 INFO [xa-todo-servie,] 1948 — [0:0:0:0:1:2181)] org.apache.zookeeper.ClientCnxn : Opening socket connection to server 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
2018-08-28 22:49:21.581 WARN [xa-todo-servie,] 1948 — [0:0:0:0:1:2181)] org.apache.zookeeper.ClientCnxn : Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_77]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_77]
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361) ~[zookeeper-3.4.8.jar:3.4.8–1]
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141) ~[zookeeper-3.4.8.jar:3.4.8–1]

  • 原因分析:

    报了zookeeper连接异常的错误,因为我的kafka装在虚拟机的docker中,暂时没有连接,demo是本地跑的。所以我想注释了插件,先把demo跑通,我只是想先跑通demo啊

  • 疑问:

    提出您对于遇到和解决该问题时的疑问

本地启动异常?

resources 文件夹下创建application-default.yml 文件。

添加配置

spring:
  cloud:
    bus:
      enabled: false
  sleuth:
    stream:
      enabled: false
hystrix:
  stream:
    queue:
      enabled: false

这个文件在我项目里是application.yml,我把原来的都注释了,然后添加了你说的代码,还是报错,应用启动失败。


这个是demo程序


这个是application.yml文件

clean 一下,然后重新import下依赖,再启动

在每次运行之前,我都会clean一下,重新构建以后再跑,然而并没有什么卵用

麻烦贴一下pom文件和错误的堆栈信息。还有你的的demo项目是从https://github.com/wmzzh117/choerodon-todo-service 这里clone的吗

代码克隆地址为https://code.choerodon.com.cn/ora-xadc/xa-todo-servie.git,看了论坛前面的帖子,我把pom文件里Choerodon的版本号改了,重新构建了。看了一下代码。里面连接的各种插件都以写好。但是刚接触这个,我是想先跑通demo。所以我放弃了直接跑那个工程了,现在按照官网文档新建项目,一步一步来。初步还是可以跑起来的。慢慢的再添加那些插件,对学习有好处。谢谢耐心的解答。

我拉了下代码本地是可以跑通过的。你可以检索下错误信息,看起来并不像是代码的错误,而像是IDE或者jdk的问题。