我有入口shell脚本,它接受参数-a -b.
我有工作的docker-compose.yml文件,我用指令覆盖tomcat的入口点:
entrypoint: /usr/local/tomcat/entrypoint.sh -a param1 -b param2
Run Code Online (Sandbox Code Playgroud)
什么是docker run替代品?
docker run --entrypoint "/usr/local/tomcat/entrypoint.sh -a param1 -b param2" tomcat:jre8
Run Code Online (Sandbox Code Playgroud)
不起作用
我明白了:
docker: Error response from daemon:
invalid header field value "oci runtime error: container_linux.go:247:
starting container process caused \"exec:
\\\"/usr/local/tomcat/entrypoint.sh -a param1 -b param2\\\":
stat /usr/local/tomcat/entrypoint.sh -a param1 -b param2:
no such file or directory\"\n".
Run Code Online (Sandbox Code Playgroud)
供参考:
docker run --entrypoint "/usr/local/tomcat/entrypoint.sh" tomcat:jre8
Run Code Online (Sandbox Code Playgroud)
从Docker的角度来看,但显然脚本失败了
我想编写一个自动执行以下操作的bash脚本:
进入内部运行容器
docker exec -it CONTAINER_NAME /bin/bash
Run Code Online (Sandbox Code Playgroud)
执行一些命令:
cat /dev/null > /usr/local/tomcat/logs/app.log
exit
Run Code Online (Sandbox Code Playgroud)
有问题的部分是何时docker exec
执行.创建了新shell,但未执行其他命令.
有办法解决吗?
关于时间依赖单元测试的问题,我有一个问题
假设我构建了包含服务接口及其实现的Spring应用程序
如果我想在测试中更改时钟,我将不得不"污染"生产代码和接口,例如setClock
方法如下:
public interface MyService {
void heavyBusinessLogic();
void setClock(Clock clock);
}
@Service
public class MyServiceImpl implements MyService {
private Clock clock = Clock.systemDefaultZone();
@Override
public void heavyBusinessLogic() {
if (LocalDate.now(clock)...) {
...
}
}
@Override
public void setClock(Clock clock) {
this.clock = clock;
}
}
Run Code Online (Sandbox Code Playgroud)
在测试中,我可以调用,例如:
service.setClock(Clock.fixed(Instant.parse("2017-02-14T01:22:00Z"), ZoneOffset.UTC));
Run Code Online (Sandbox Code Playgroud)
如何在Spring中消除这种跨领域的关注?
我想坚持使用java.time.Clock(我不想使用Joda)
我有 2 个 C# 项目:Project.csproj
和Project.Tests.csproj
.
Project.Tests.csproj
包含ProjectReference
:
<ItemGroup>
<ProjectReference Include="../Project/Project.csproj" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
我使用浮动版本的依赖项,并且还启用了锁定文件:
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<RestoreLockedMode>false</RestoreLockedMode>
Run Code Online (Sandbox Code Playgroud)
当我执行时dotnet restore --locked-mode
,我得到
/usr/share/dotnet/sdk/3.1.409/NuGet.targets(128,5): error NU1004: The packages lock file is inconsistent with the project dependencies so restore can't be run in locked mode. Disable the RestoreLockedMode MSBuild property or pass an explicit --force-evaluate option to run restore to update the lock file.
Run Code Online (Sandbox Code Playgroud)
当我尝试建议时dotnet restore --force-evaluate
,它已正确恢复,但锁定文件没有任何更改。有趣的是,当我dotnet restore --locked-mode
立即执行时,它同样失败了error NU1004
您知道如何克服这个问题吗?有没有办法告诉 NuGet …
鉴于我有 Spring Data 存储库并且我在方法上放置了Cacheable注释findAll
:
@Repository
@CacheConfig(cacheNames = TEMPLATE_CACHE)
public interface TemplateRepository extends JpaRepository<Template, Long> {
@Override
@Cacheable
List<Template> findAll();
}
Run Code Online (Sandbox Code Playgroud)
Intellij IDEA 显示警告:
Spring Team recommends that you only annotate concrete classes (and methods of concrete classes) with the @Cache* annotation, as opposed to annotating interfaces.
You certainly can place the @Cache* annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. …
Run Code Online (Sandbox Code Playgroud) 想象一下,我有基于Dockerfile的Docker映像,我将对其进行标记并将其推送到Docker注册表中
随着时间的流逝,我更改了Dockerfile(添加/更改新指令,...)
现在,我将再次使用与最初使用的标签相同的标签来标记新映像,并将其推入Docker注册表
什么是Groovy的Java 8替代品.map()
?
例:
List<String> codes = events
.stream()
.map(event -> event.getCode())
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
我试图做
events.each { it; return it.getCode() }.collect() as String[]
Run Code Online (Sandbox Code Playgroud)
但我得到List
的String
S,但toString()
表示,而代码
假设我有我的 custom RuntimeException
,MyEntity
JPA在哪里@Entity
:
@Getter
public class MyEntityAlreadyExistingException extends RuntimeException {
private final MyEntity myEntity;
public MyEntityAlreadyExistingException(MyEntity myEntity) {
super(MessageFormat.format("MyEntity with name \"{0}\" already exists", myEntity.getName()));
this.myEntity = myEntity;
}
}
Run Code Online (Sandbox Code Playgroud)
声纳提示我进行myEntity
瞬态或可序列化。
我应该如何处理这种情况?
我不使用任何 RMI,也不使用任何远程处理。它是一个相对简单的 Spring Boot Web 应用程序,带有 JPA。
如果我可以myEntity
序列化,我以后可以利用哪些优势?
假设我有带属性的 Airport 实体:
@Column(nullable = false, unique = true)
private final String code;
Run Code Online (Sandbox Code Playgroud)
显然,当我使用之前使用的代码持久化实体时,它会抛出 DataIntegrityViolationException
我有启用了 Spring Data REST 的 Spring Boot 应用程序。
对于这种情况,RepositoryRestExceptionHandler
需要处理DataIntegrityViolationException
s 并将它们映射到409状态代码:
@ExceptionHandler({ OptimisticLockingFailureException.class, DataIntegrityViolationException.class })
ResponseEntity<ExceptionMessage> handleConflict(Exception o_O) {
return errorResponse(HttpStatus.CONFLICT, new HttpHeaders(), o_O);
}
Run Code Online (Sandbox Code Playgroud)
典型的响应如下所示:
HTTP/1.1 409
X-Application-Context: application
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 28 Apr 2017 10:21:31 GMT
{
"cause" : {
"cause" : {
"cause" : null,
"message" : "Unique index or primary key violation: \"UK_X9RMMVEVTW274QQXGT73OQ74_INDEX_C …
Run Code Online (Sandbox Code Playgroud) 我有基于Spring Data REST的应用程序和存储库
public interface CriterionRepository extends JpaRepository<Criterion, Long> {
}
Run Code Online (Sandbox Code Playgroud)
而Criterion
基类是:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Criterion extends AbstractEntity {}
Run Code Online (Sandbox Code Playgroud)
并且NameCriterion
是它的子类
@Entity
public class NameCriterion extends Criterion {
private final String name;
}
Run Code Online (Sandbox Code Playgroud)
Spring Data REST将存储库导出为REST资源,可以在http:// localhost:8080/api/criteria /访问它
导出的资源如下所示:
{
"_embedded": {
"nameCriteria": [{
"_links": {
"self": {
"href": "http://localhost:8080/api/nameCriterion/1"
},
"nameCriterion": {
"href": "http://localhost:8080/api/nameCriterion/1"
}
}
}
]
},
"_links": {
"self": {
"href": "http://localhost:8080/api/criteria"
},
"profile": {
"href": "http://localhost:8080/api/profile/criteria" …
Run Code Online (Sandbox Code Playgroud)