小编Lun*_*ape的帖子

在 aws ec2 实例上安装 npm 抛出 EACCES

我已使用 ElasticBeanstalk 在 AWS 上创建了一个预配置的 node.js 实例,但该应用程序无法正常运行。所以我连接到实例并发现没有节点或角度cli,所以我手动安装了它们。然后我尝试在应用程序文件夹中运行 npm install 但失败,这是输出错误。

[ec2-user@ip current]$ npm install
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/tslib
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@ngx-loading-bar/core
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/animations
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/common
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/compiler
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/core
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/forms
npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/http
npm WARN …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services node.js

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

Intellij 无法在 Spring Boot 中解析百里香模板的变量

这个帖子说问题已经解决了,但即使我有最新版本的 IntelliJ Ultimate,我似乎仍然有问题。

implementation "org.springframework.boot:spring-boot-starter-thymeleaf"在我的 gradle 设置中。

在此处输入图片说明

该应用程序工作正常,但我希望能够使用IntelliJ 提供的导航到声明功能thymeleaf-spring我的项目中已经有模块了。

intellij-idea thymeleaf spring-boot

7
推荐指数
0
解决办法
1395
查看次数

docker 镜像在构建后消失

下面是我的控制台日志:

jy03154586@ubuntu:~/Works$ docker build -t ui .
Sending build context to Docker daemon  50.18MB
Step 1/9 : FROM node:carbon-alpine as build
 ---> adc4b0f5bc53
...
Step 9/9 : COPY --from=build /app/dist /usr/share/nginx/html
 ---> 997cc6252b83
Successfully built 997cc6252b83
Successfully tagged ui:latest
jy03154586@ubuntu:~/Works$ docker images ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jy03154586@ubuntu:~/Works$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
jy03154586@ubuntu:~/Works$ 
Run Code Online (Sandbox Code Playgroud)

我尝试构建一个 angularjs 应用程序镜像,但是构建的镜像在哪里?表明successfully built

docker

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

DateTimeFormatter 将 LocalDate 序列化为一个月的第 1/2/3 号

我想显示LocalDate为:

first day: 1st;
second day: 2nd;
third day: 3rd;
all rest days: Nth.
Run Code Online (Sandbox Code Playgroud)

例如1980-10-1作为1st Oct 1980

我可以使用 对其进行序列化,不包括前 3 天DateTimeFormatter.ofPattern("dth MMM yyyy")。由于前 3 天与其余日期的模式不同,如何构建格式化程序来序列化前 3 天?

java

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

如何修改Spring存储库搜索REST API的页面类型结果?

我有一个 HotelRepository,它有一个命名方法,它返回一个默认Page<Hotel>项作为结果而不是一个列表。

我想将内容类型更改HotelHotelDto在页面中,因为 DTO 具有我想要显示的自定义参数。我已经有一个构造函数可以将 Hotel 转换为 HotelDto。

我的尝试:

Page<Hotel> hotels = dao.findAll(pageRequest);
return new PageImpl<>(
                hotels.getContent().stream()
                        .map(hotel -> new HotelListItemDto(hotel, hotel.getSupplier())).collect(Collectors.toList()),
                pageRequest, hotels.getContent().size());
Run Code Online (Sandbox Code Playgroud)

问题是它只操作结果的一页。当然,我可以先把所有的结果作为一个列表,然后根据列表创建一个页面,但是这样就失去了Page(我认为返回页面会提高搜索请求的性能)的优势。

那么我应该怎么做才能保持页面优势,但仍然可以自定义输出?

java spring pagination

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

基于 docker 环境变量切换 spring 配置文件不起作用

docker-compose.yml:

services:
  server:
    image: server:latest
    environment:
    - SPRING_PROFILES_ACTIVE=dev
    ports:
    - 8080:8080
    - 18080:18080
Run Code Online (Sandbox Code Playgroud)

Dockerfile:

FROM openjdk:8-jre-alpine

ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
    SLEEP=0 \
    JAVA_OPTS="" \

RUN adduser -D -s /bin/sh server
WORKDIR /home/server

ADD entrypoint.sh entrypoint.sh
RUN chmod 755 entrypoint.sh && chown server:server entrypoint.sh
USER server

ENTRYPOINT ["./entrypoint.sh"]
# expose server ports
EXPOSE 8080 18080

ADD *.jar server.jar
Run Code Online (Sandbox Code Playgroud)

入口点.sh:

#!/bin/sh

echo "The application will start in ${SLEEP}s..." && sleep ${SLEEP}
exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar "${HOME}/server.jar" "$@"
Run Code Online (Sandbox Code Playgroud)

我有 3 个 application.yml: application.yml …

docker spring-boot docker-compose

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

如何检查非模板类和模板类之间的类型相等性?

假设我有

class A {};

template<typename T, typename U> class Wrapper {};
Run Code Online (Sandbox Code Playgroud)

我正在尝试检查包装器的第一个内部类型是否为A.

typeCheck(new A(), new Wrapper<A,B>);  // expect true
typeCheck(new A(), new Wrapper<C,B>);  // expect false
Run Code Online (Sandbox Code Playgroud)

最好的方法是什么?


我尝试过模板部分专业化,但没有运气。

这是我尝试过的代码:

template<typename T> struct get_inner {
  using type = T;
}

template<typename T, typename U>
struct get_inner<Wrapper<T,U>> {
  using type = T;
}

std::cout<< typeid(get_inner<decltype(new Wrapper<A,B>)>::type);
Run Code Online (Sandbox Code Playgroud)

控制台显示相同的包装类型而不是内部类型A。这里有什么错误吗?

c++ templates typechecking specialization type-traits

3
推荐指数
1
解决办法
97
查看次数

@Configuration和@configurationProperties之间的SpringBoot区别

spring boot文档中@ConfigurationProperties

从带@ConfigurationProperties注释的项目生成您自己的配置元数据文件

我尝试在配置类上单独使用use @Configuration@ConfigurationProperties

@Component
//@Configuration
@ConfigurationProperties 
@EnableSpringDataWebSupport
@EnableAsync
public class AppConfig {
    ...
}
Run Code Online (Sandbox Code Playgroud)

我没有发现任何明显的差异。

@ConfigurationProperties或的用途是@Configuration什么?

spring-boot

2
推荐指数
2
解决办法
2881
查看次数

Webclient 发送没有正文的 POST 将得到 IllegalStateException

我正在尝试在WebClient没有请求正文的情况下对 api 进行 POST 调用(该 api 不需要正文):

\n\n
webClient.post()\n         .uri("url")\n         .retrieve()\n         .bodyToMono(CustomResponse.class);\n
Run Code Online (Sandbox Code Playgroud)\n\n

但调用返回异常:

\n\n
\n

底层 HTTP 客户端已完成,\n 未发出响应。java.lang.IllegalStateException: 底层 HTTP 客户端已完成,\n 未发出响应。

\n
\n\n

对于另一个需要请求正文的 API,我可以成功地进行 POST 调用,没有任何问题:

\n\n
webClient.post()\n         .uri("url")\n         .bodyValue("value")\n         .retrieve()\n         .bodyToMono(CustomResponse.class);\n
Run Code Online (Sandbox Code Playgroud)\n\n

问题是否与 WebClient\xe2\x80\x99s 请求正文有关?我如何解决它?

\n\n

更新

\n\n

发生错误的原因是我ContentType通过 添加了 Webclient 的标头.defaultHeader("ContentType", JSON)。\n删除标头后问题就消失了。

\n

java spring-boot spring-webflux

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

当类字段是集合时,AssertJ usingRecursiveComparison 失败

class Person {
  private List<Phone> phones;
}
class Phone {
  private String number;
}

assertThat(result).usingRecursiveComparison()
        .ignoringCollectionOrder()
        .isEqualTo(expectedPerson);
Run Code Online (Sandbox Code Playgroud)

具有expectedPerson相同数量的电话和电话号码,但测试失败,因为列表引用不同。如果我没记错的话,usingRecursiveComparison只会比较价值。那么为什么这里失败了呢?

java unit-testing assertj junit5

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

单向多对一的Spring数据jpa规范

public class Hotel{
    @ManyToOne(optional = false)
    @NotNull
    @JoinColumn(name = "hotel_city", referencedColumnName = "city_id")
    private City city;
}

public class City{
    @Column(name = "public_id", updatable = false, unique = true)
    @NotEmpty
    private String publicId;
}
Run Code Online (Sandbox Code Playgroud)

我想找到城市的 publicId 等于给定字符串的所有酒店。

public Predicate toPredicate(Root<Hotel> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                Subquery<City> subquery = query.subquery(City.class);
                Root<City> subRoot = subquery.from(City.class);
                Predicate cityIdPredicate = cb.equal(subRoot.get("publicId"), criteria.getValue().toString());

                return cb.equal(root.get("city"), cityIdPredicate);
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用上面的代码

  1. 在城市表中选择 publicId 等于给定字符串的城市;
  2. 获取酒店所在城市并将其与#1 的结果进行比较。

好像出问题了。这是我第一次使用规范,任何提示都是有帮助的。谢谢。

java spring-data-jpa

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