基于docker容器的部署

  1. 创建Ubuntu18TextVMI(参考手册http://man.kinginsai.com/ --> 创建windows和Linux虚拟机 --> 创建Linux虚拟机(命令行模式,xshell/securecrt远程连接))

  2. 等待Ubuntu18TextVMI主机正常运行后(创建完成不等于正常运行,参考手册http://man.kinginsai.com/ --> 创建windows和Linux虚拟机),在web workspace中将编译的java包拷贝到Ubuntu18TextVMI主机

在这里插入图片描述

  1. 创建tools workspace,并使用"she tools"的方式连接Ubuntu18TextVMI主机

在这里插入图片描述

在这里插入图片描述

  1. 在Ubuntu18TextVMI主机中进行以下操作

1). 在~/目录下创建petclinic目录: mkdir petclinic, 然后 cd petclinic

2). touch Dockerfile

3). 在Dockerfile中输入以下内容

FROM openjdk:8u232-jre-slim

ENV app_id "1"
ENV spring_datasource_username "root"
ENV spring_datasource_password "Yhf@1018"
ENV database_url "jdbc:mysql://localhost:3306/petclinic"

COPY ./spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar /opt

RUN rm -rf /etc/localtime && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    printf "#! /bin/bash\nset -e\n exec \"\$@\"" > /entrypoint.sh && chmod a+x /entrypoint.sh && chmod a+x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

WORKDIR /opt

CMD ["java", "-Duser.timezone=Asia/Shanghai", "-jar", "./spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar", \
"--spring.datasource.username=${spring_datasource_username}", \
"--spring.datasource.password=${spring_datasource_password}", \
"--spring.datasource.url=${database_url}", \
"--app.id=${app_id}"]

4). cp ../spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar ./

5). docker build --network=host --no-cache -t r.kinginsai.com/petclinic:7.8.0 .

注意:最后有一个英文的句号。

如果你的服务端没有外网条件,请按照repository.tar.gz的办法找到"openjdk_8u232-jre-slim.tar"并上传到web workspace中, 然后使用"将编译的java包拷贝到Ubuntu18TextVMI主机"的方式上传到Ubuntu18TextVMI主机,然后使用docker load -i openjdk_8u232-jre-slim.tar加载openjdk:8u232-jre-slim镜像

详细操作过程参见以下视频,

6). docker images | grep r.kinginsai 查看r.kinginsai.com/petclinic:7.8.0镜像的情况

7). 运行mysql容器(如果你的服务端没有外网条件,请加载mysql_5.7-debian.tar)

docker run -d --name mysql --restart=always -e MYSQL_ROOT_PASSWORD=Yhf@1018 mysql:5.7-debian

8). 运行docker inspect -f {{.State.Running}} mysql 查看mysql容器运行状态,结果为true证明mysql容器运行完成

9). 执行mysql数据库初始化:

docker exec mysql sh -c 'mysql -uroot -p"Yhf@1018" -e "CREATE DATABASE IF NOT EXISTS petclinic;"'

如果出现

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

或者

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

请等待一会后再次执行,直到执行成功为止。

docker exec mysql sh -c 'mysql -uroot -p"Yhf@1018" -e "ALTER DATABASE petclinic DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"'

执行过程如下,

root@ssxy:~# docker exec mysql sh -c 'mysql -uroot -p"Yhf@1018" -e "CREATE DATABASE IF NOT EXISTS petclinic;"'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@ssxy:~# docker exec mysql sh -c 'mysql -uroot -p"Yhf@1018" -e "CREATE DATABASE IF NOT EXISTS petclinic;"'
mysql: [Warning] Using a password on the command line interface can be insecure.
root@ssxy:~# docker exec mysql sh -c 'mysql -uroot -p"Yhf@1018" -e "ALTER DATABASE petclinic DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"'
mysql: [Warning] Using a password on the command line interface can be insecure.
root@ssxy:~# 

10). 启动petclinic容器

ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' mysql)

docker run -d --name petclinic -p 8080:8080 --restart=always -e spring.profiles.active=mysql -e spring_datasource_password=Yhf@1018 -e database_url="jdbc:mysql://$ip:3306/petclinic" r.kinginsai.com/petclinic:7.8.0

其中,"-p 8080:8080"中的第一个8080代表宿主机的端口,第二个8080代表容器的端口

11). docker logs -f petclinic 查看petclinic启动过程,并等待初始化完成(ctrl + c可退出)

在这里插入图片描述

如果遇到出错,可通过 docker stop petclinic、docker rm petclinic 删除容器

12). 点击tools-dev中tools按钮,并打开chrome浏览器,输入Ubuntu18TextVMI主机:8080打开web界面

在这里插入图片描述

  1. reboot Ubuntu18TextVMI主机,再次打开web界面 + docker logs -f petclinic 查看情况

详细操作过程参见以下视频,

常见问题及其解决方案

  1. 在"启动petclinic容器"时,使用docker logs -f petclinic出现以下日志信息,

              |\      _,,,--,,_
             /,`.-'`'   ._  \-;;,_
  _______ __|,4-  ) )_   .;.(__`'-'__     ___ __    _ ___ _______
 |       | '---''(_/._)-'(_\_)   |   |   |   |  |  | |   |       |
 |    _  |    ___|_     _|       |   |   |   |   |_| |   |       | __ _ _
 |   |_| |   |___  |   | |       |   |   |   |       |   |       | \ \ \ \
 |    ___|    ___| |   | |      _|   |___|   |  _    |   |      _|  \ \ \ \
 |   |   |   |___  |   | |     |_|       |   | | |   |   |     |_    ) ) ) )
 |___|   |_______| |___| |_______|_______|___|_|  |__|___|_______|  / / / /
 ==================================================================/_/_/_/

:: Built with Spring Boot :: 2.2.5.RELEASE


2023-07-28 09:52:27.492  INFO 1 --- [           main] o.s.s.petclinic.PetClinicApplication     : Starting PetClinicApplication v2.2.0.BUILD-SNAPSHOT on ca1af1ea720b with PID 1 (/opt/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar started by root in /opt)
2023-07-28 09:52:27.685  INFO 1 --- [           main] o.s.s.petclinic.PetClinicApplication     : The following profiles are active: mysql
2023-07-28 09:53:00.401  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-07-28 09:53:02.327  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1607ms. Found 4 JPA repository interfaces.
2023-07-28 09:53:30.393  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-07-28 09:53:30.709  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-07-28 09:53:30.716  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
2023-07-28 09:53:32.764  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-07-28 09:53:32.782  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 63478 ms
2023-07-28 09:53:44.892  INFO 1 --- [           main] org.ehcache.core.EhcacheManager          : Cache 'vets' created in EhcacheManager.
2023-07-28 09:53:45.253  INFO 1 --- [           main] org.ehcache.jsr107.Eh107CacheManager     : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=vets
2023-07-28 09:53:45.472  INFO 1 --- [           main] org.ehcache.jsr107.Eh107CacheManager     : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=vets
2023-07-28 09:53:47.720  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-07-28 09:53:59.450  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-07-28 09:54:17.284  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-07-28 09:54:20.825  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.12.Final
2023-07-28 09:54:24.185  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2023-07-28 09:54:26.509  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2023-07-28 09:54:51.475  INFO 1 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-07-28 09:54:51.702  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-07-28 09:55:01.828  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ownerController' defined in URL [jar:file:/opt/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar!/BOOT-INF/classes!/org/springframework/samples/petclinic/owner/OwnerController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ownerRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Using named parameters for method public abstract java.util.Collection org.springframework.samples.petclinic.owner.OwnerRepository.findByLastName(java.lang.String) but parameter 'Optional[lastName]' not found in annotated query 'SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%'!
2023-07-28 09:55:01.870  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-07-28 09:55:01.923  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2023-07-28 09:55:02.157  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2023-07-28 09:55:02.383  INFO 1 --- [           main] org.ehcache.core.EhcacheManager          : Cache 'vets' removed from EhcacheManager.
2023-07-28 09:55:02.557  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-07-28 09:55:02.970  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-07-28 09:55:03.115 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ownerController' defined in URL [jar:file:/opt/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar!/BOOT-INF/classes!/org/springframework/samples/petclinic/owner/OwnerController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ownerRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Using named parameters for method public abstract java.util.Collection org.springframework.samples.petclinic.owner.OwnerRepository.findByLastName(java.lang.String) but parameter 'Optional[lastName]' not found in annotated query 'SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%'!
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.samples.petclinic.PetClinicApplication.main(PetClinicApplication.java:32) [classes!/:2.2.0.BUILD-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_232]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_232]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_232]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_232]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ownerRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Using named parameters for method public abstract java.util.Collection org.springframework.samples.petclinic.owner.OwnerRepository.findByLastName(java.lang.String) but parameter 'Optional[lastName]' not found in annotated query 'SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%'!
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        ... 27 common frames omitted
Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract java.util.Collection org.springframework.samples.petclinic.owner.OwnerRepository.findByLastName(java.lang.String) but parameter 'Optional[lastName]' not found in annotated query 'SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%'!
        at org.springframework.data.jpa.repository.query.JpaQueryMethod.assertParameterNamesInAnnotatedQuery(JpaQueryMethod.java:156) ~[spring-data-jpa-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:135) ~[spring-data-jpa-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:78) ~[spring-data-jpa-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:574) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:567) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_232]
        at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_232]
        at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1051) ~[na:1.8.0_232]
        at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_232]
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[na:1.8.0_232]
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[na:1.8.0_232]
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_232]
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_232]
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) ~[na:1.8.0_232]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:569) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_232]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:332) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.util.Lazy.getNullable(Lazy.java:212) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121) ~[spring-data-jpa-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
        ... 38 common frames omitted

这种错误出现的原因是Ubuntu18TextVMI主机使用模拟的方式创建的、即She平台运行在没有硬件虚拟化支撑的服务器集群中。解决方法是

方案1. 在"执行mysql数据库初始化"后,即执行完

docker exec mysql sh -c 'mysql -uroot -p"Yhf@1018" -e "ALTER DATABASE petclinic DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"'

后,需要手动建表并加载数据

A. 从web workspace中拷贝schema.sql/data.sql到Ubuntu18TextVMI主机,

在这里插入图片描述

B. 在Ubuntu18TextVMI主机中将以上两个文件copy到mysql容器中,

docker cp schema.sql mysql://root/
docker cp data.sql mysql://root/

C. 进入mysql容器命令行

docker exec -it mysql /bin/bash

然后执行

mysql -uroot -p"Yhf@1018" petclinic < /root/schema.sql
mysql -uroot -p"Yhf@1018" petclinic < /root/data.sql
exit

在这里插入图片描述

方案2. 等

由于使用了 --restart=always 参数,多次失败后最后会成功的,但是等待多久是无法事先预知的。

  1. She平台使用的registry.kinginsai.com作为镜像名称前缀,为什么这里打包使用r.kinginsai.com

因为前者是She平台内部组件使用,是经过严格测试的;而后者仅仅是测试案例中临时镜像使用,使用r.kinginsai.com可以避免这种混淆