我已经按照spring.io上的入门教程来构建REEST服务https://spring.io/guides/gs/rest-service/.问题是本教程仅解释了如何使用spring boot嵌入tomcat来生成独立运行的jar.
有没有办法从头开始创建一个项目来生成一个战争来部署,例如在已经存在的tomcat实例上?
PS:我发现一个先前的线程Spring RESTful Service作为WAR而不是Tomcat中的JAR在 stackoverflow上有关同一个问题.问题是接受的答案和建议并没有完全解决我的问题,因为我不是在寻找修改独立应用程序弹簧启动项目的方法,以便它可以在外部tomcat容器上运行,但是想找到一个"清洁"解决方案根本不涉及弹簧靴.(我不确定如何在这里表现,在stackoverflow上仍然很新.我希望打开一个新问题是正确的程序).
我有一个诗歌项目。我的环境是 Windows 机器上的 Conda 22.9.0,诗歌版本为 1.2.2:
\n这是我的 pyproject.toml 文件:
\n[tool.poetry]\nname = "myproject"\nversion = "0.1.0"\ndescription = ""\n\n[tool.poetry.dependencies]\n# REVIEW DEPENDENCIES\npython = ">=3.7,<3.11"\nnumpy = "*"\ntensorflow = "^2.8"\n\n[build-system]\nrequires = ["poetry>=0.12"]\nbuild-backend = "poetry.masonry.api"\n\n[tool.poetry.scripts]\nstart = "myproject.main:start"\nRun Code Online (Sandbox Code Playgroud)\nmyproject\\main.py 模块包含:
\nimport tensorflow as tf\n\ndef start():\n if tf.test.is_gpu_available():\n print("TensorFlow is using a GPU.")\n else:\n print("TensorFlow is NOT using a GPU.")\nRun Code Online (Sandbox Code Playgroud)\n如果我这样做poetry install,它似乎工作正常:
Creating virtualenv myproject in D:\\Projects\\myproject\\dev\\myproject-series-forecast\\.venv\nUpdating dependencies\nResolving dependencies...\n\nWriting lock file\n\nPackage operations: 41 installs, 0 updates, 0 removals\n\n\xe2\x80\xa2 Installing certifi (2022.12.7)\n\xe2\x80\xa2 …Run Code Online (Sandbox Code Playgroud) 我正在编写一个iOS/Swift应用程序,它每隔X分钟从REST服务中读取数据并相应地更新UI.
现在我希望当应用程序放在后台时,从REST服务读取一个任务,每隔X分钟读取一次,如果刚读取的数据满足给定条件,则会显示一条通知,提示用户带来应用程序回到前台.
在我的搜索中,我读过在applicationDidEnterBackground活动期间,我应该开始执行任务beginBackgroundTaskWithExpirationHandler.
问题是,如果我已经正确理解,这允许最多10/15分钟,如果任务没有停止,应用程序终止endBackgroundUpdateTask,而我希望任务继续无限期地轮询服务(至少直到用户从应用程序的设置中禁用它)
这种功能如何正常执行?是否存在一些解决此类问题的常见解决方案或最佳实践?
在最近的Windows 10更新后,我的流浪虚拟机停止工作,拒绝启动vagrant up.问题似乎与我用于我的VM的Virtualbox提供程序有关,并且只有在Vagrantfile中配置了private_network时才会出现问题,而端口转发和public_network似乎都有效.
我第一次将操作系统从Windows 7更新到Windows 10时,我已经遇到了类似的问题.在这种情况下,我在Virtualbox的票14040处解决了问题.但是,在应用新的Windows更新后,补丁解决方案不再有效.
我还试图将VirtualBox和Vagrant都更新到他们的最新版本,但这并没有改变任何东西.
这是我的Windows/Virtualbox/Vagrant版本:
Microsoft Windows 10 version 1511 (build SO 10586.14)
VirtualBox version 5.0.10 r104061
Vagrant version 1.7.4
Run Code Online (Sandbox Code Playgroud)
这是我启动时遇到的错误vagrant up:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 2222 …Run Code Online (Sandbox Code Playgroud) 我有一个input.json像以下一样的json文件:
{
"variable" : "${ENV_VAR}"
}
Run Code Online (Sandbox Code Playgroud)
当然,我可以从bash中调用envsubst,如下所示:
$ export ENV_VAR=myvalue
$ envsubst < input.json > output.json
$ cat output.json
{
"variable" : "myvalue"
}
Run Code Online (Sandbox Code Playgroud)
现在,我希望我可以在input.json中为ENV_VAR未设置的情况设置变量的默认值,如下例所示,不幸的是,在下面的示例中可以看到它不起作用:
$ cat input.json
{
"variable" : "${ENV_VAR:=defaultvalue}"
}
$ export ENV_VAR=newvalue
$ envsubst < input.json > output.json
$ cat output.json
{
"variable" : "${ENV_VAR:=defaultvalue}"
}
$ unset ENV_VAR
$ envsubst < input.json > output.json
$ cat output.json
{
"variable" : "${ENV_VAR:=defaultvalue}"
}
Run Code Online (Sandbox Code Playgroud)
有什么好奇的,如果我执行envsubst,如下例所示(不涉及输入文件),它的工作原理
$ export ENV_VAR=myvalue
$ echo "value is ${ENV_VAR:=defaultvalue}" …Run Code Online (Sandbox Code Playgroud) 我正在开发Spring Cloud Eureka微服务应用程序.我希望我的服务通过Eureka优先方法连接到配置服务.微服务被打包为docker容器并通过docker-compose进行部署.该申请由以下人员组成:
myapp-service-registry:使用Spring Cloud Eureka实现的服务注册服务myapp-config-service:Spring Cloud配置服务服务器myapp-service-test:一个示例微服务,它应该尝试通过Eureka优先方法连接到配置服务来获取配置数据. 与配置服务的连接失败,如下所述.首先是一些配置数据:
这里myapp-service-registry的application.yml:
server:
port: ${PORT:8761}
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
Run Code Online (Sandbox Code Playgroud)
这是myapp-config-service's application.yml:
server:
port: ${MYAPP_CONFIG_SERVICE_PORT:8888}
spring:
cloud:
config:
server:
git:
uri: ${MYAPP_CONFIG_SERVICE_GIT_URI}
config:
name: myapp-config-service
# eureka service registry client
eureka:
client:
serviceUrl:
defaultZone: http://${SERVICE_REGISTRY_HOST}:${SERVICE_REGISTRY_PORT}/eureka/
instance:
preferIpAddress: true
Run Code Online (Sandbox Code Playgroud)
配置服务器和客户端初始化为https://github.com/spring-cloud-samples/tests中的样本configserver-eureka和eureka-first样本:
myapp-config-service的bootstrap.yml是:
spring:
application:
name: myapp-config-service
cloud:
config:
discovery:
enabled: …Run Code Online (Sandbox Code Playgroud) spring spring-boot microservices spring-cloud netflix-eureka
我正在尝试创建一个 Maven 原型来从预定义的模板生成多个项目。
\n\narchetype生成的模板项目是一个Spring Boot服务。以下是原型项目文件夹树的内容:
\n\nmy-archetype\n\xc2\xa6 pom.xml\n\xc2\xa6\n+---src\n\xc2\xa6 +---main\n\xc2\xa6 \xc2\xa6 +---resources\n\xc2\xa6 \xc2\xa6 +---archetype-resources\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 mvnw\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 mvnw.cmd\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 pom.xml\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 rebuild.sh\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6\n\xc2\xa6 \xc2\xa6 \xc2\xa6 +---src\n\xc2\xa6 \xc2\xa6 \xc2\xa6 +---main\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 +---docker\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 Dockerfile\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 +---java\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 __moduleClassName__ServiceApplication.java\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 __moduleClassName__ServiceController.java\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 +---resources\n\xc2\xa6 \xc2\xa6 \xc2\xa6 \xc2\xa6 application.yml\n\xc2\xa6 \xc2\xa6 \xc2\xa6 …Run Code Online (Sandbox Code Playgroud) 我有一组 Spring Boot 应用程序,我想将它们打包为 docker 容器。我正在使用以下 Dockerfile 为其中一项服务创建容器:
FROM java:8
VOLUME /tmp
ADD myservice.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Run Code Online (Sandbox Code Playgroud)
在内部,服务访问一些环境属性,例如:
@Value("${my.test.param:default}")
String testParam;
.
.
.
logger.info("param value is = "+testParam);
Run Code Online (Sandbox Code Playgroud)
现在,我希望能够通过这样的docker run命令行覆盖此设置
docker run -p 8080:8080 -e my.test.param=changed mygroup/myservice:0.0.1
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎不起作用。我一直看到参数的默认值my.test.param。我搜索-e了ENTRYPOINT在行尾自动添加所有参数的方法,但没有找到。有没有一些通用的解决方案?
我尝试gitlab/gitlab-ce按照http://doc.gitlab.com/omnibus/docker上的说明,通过docker compose 将GitLab CE版作为docker容器()运行。
问题是,每次我开始时docker-compose up -d,容器在大约一分钟后崩溃/退出。我收集了所有可能有用的信息,有些厨师相关的错误消息我无法解密。该环境在Ubuntu Vagrant虚拟机内部运行。
我尝试使用图像的其他标记版本代替:latest,但是得到了相似的结果。
docker-compose.yml相关代码段:
gitlab:
image: gitlab/gitlab-ce
container_name: my_gitlab
volumes:
- ./runtime/gitlab/config:/etc/gitlab
- ./runtime/gitlab/data:/var/opt/gitlab
- ./runtime/gitlab/logs:/var/log/gitlab
ports:
- 443:443
- 22:22
- 8082:80
Run Code Online (Sandbox Code Playgroud)
以下是保存在./runtime/gitlab/logs中的日志文件(/ var / log / gitlab的卷)
# Logfile created on 2016-04-28 08:07:43 +0000 by logger.rb/44203
[2016-04-28T08:07:44+00:00] INFO: Started chef-zero at chefzero://localhost:8889 with repository at /opt/gitlab/embedded
One version per cookbook
[2016-04-28T08:07:44+00:00] INFO: Forking chef instance to converge...
[2016-04-28T08:07:44+00:00] INFO: *** Chef 12.6.0 *** …Run Code Online (Sandbox Code Playgroud) spring ×4
docker ×2
spring-boot ×2
background ×1
bash ×1
gitlab ×1
ios ×1
java ×1
linux ×1
maven ×1
python ×1
rest ×1
spring-cloud ×1
swift ×1
tensorflow ×1
tomcat ×1
vagrant ×1
virtualbox ×1
windows-10 ×1