小编Pat*_*čin的帖子

Docker使用shell脚本运行覆盖入口点,该脚本接受参数

我有入口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的角度来看,但显然脚本失败了

docker docker-compose

28
推荐指数
3
解决办法
3万
查看次数

如何在docker容器中执行命令作为bash shell脚本的一部分

我想编写一个自动执行以下操作的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,但未执行其他命令.

有办法解决吗?

bash shell docker

9
推荐指数
1
解决办法
2万
查看次数

如何在Spring中抽象java.time.Clock以进行测试

关于时间依赖单元测试的问题,我有一个问题

假设我构建了包含服务接口及其实现的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)

java junit spring jsr310

8
推荐指数
1
解决办法
6004
查看次数

恢复锁定模式失败,出现错误 NU1004:程序包锁定文件不一致

我有 2 个 C# 项目:Project.csprojProject.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 …

c# nuget .net-core

8
推荐指数
0
解决办法
1203
查看次数

缓存接口方法的注解

鉴于我有 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)

spring spring-data spring-cache

7
推荐指数
1
解决办法
3681
查看次数

docker用更改的Dockerfile和相同的标签推送到注册表

想象一下,我有基于Dockerfile的Docker映像,我将对其进行标记并将其推送到Docker注册表中

随着时间的流逝,我更改了Dockerfile(添加/更改新指令,...)

现在,我将再次使用与最初使用的标签相同的标签来标记新映像,并将其推入Docker注册表

  1. Docker注册表对新层有何反应?
  2. docker注册表对已更改的图层有何反应?
  3. 它将使用最新版本覆盖现有映像吗?
  4. 我应该使用其他标签来确保正确放置新图像吗?

docker docker-registry

6
推荐指数
1
解决办法
6577
查看次数

Groovy替代Java8的.map()流操作

什么是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)

但我得到ListStringS,但toString()表示,而代码

java groovy

6
推荐指数
1
解决办法
4331
查看次数

在 Java 中序列化自定义异常中的字段

假设我有我的 custom RuntimeExceptionMyEntityJPA在哪里@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序列化,我以后可以利用哪些优势?

java serialization transient throwable runtimeexception

6
推荐指数
1
解决办法
792
查看次数

在 Spring Data REST 中处理 DataIntegrityViolationExceptions

假设我有带属性的 Airport 实体:

@Column(nullable = false, unique = true)
private final String code;
Run Code Online (Sandbox Code Playgroud)

显然,当我使用之前使用的代码持久化实体时,它会抛出 DataIntegrityViolationException

我有启用了 Spring Data REST 的 Spring Boot 应用程序。

对于这种情况,RepositoryRestExceptionHandler需要处理DataIntegrityViolationExceptions 并将它们映射到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 spring-boot

5
推荐指数
1
解决办法
4687
查看次数

Jackson模块在Spring Data REST中处理抽象聚合根及其子类

我有基于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)

jackson spring-data spring-data-rest

5
推荐指数
1
解决办法
159
查看次数