小编sch*_*101的帖子

@Value 在单元测试中返回 null

我有一个带有端点测试配置类和单元测试的 Spring Boot 应用程序来测试我的 http 客户端。我试图从位于我的 src/test 中的 application.properties 获取我的服务器地址和端口。(所有类都在我的 src/test 中。)

这是我的配置类代码:

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import javax.xml.bind.JAXBException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import com.nulogix.billing.service.PredictionEngineService;
import com.nulogix.billing.ws.endpoint.AnalyzeEndPoint;
import com.nulogix.billing.ws.endpoint.GetVersionEndPoint;
@Configuration
public class EndPointTestConfiguration {




    @Value("${billing.engine.address}")    
    private String mockAddress;

    @Value("${billing.engine.port}")
    private String mockPort;

    @Bean
    public String getAddress() {
        String serverAddress = "http://" + mockAddress + ":" + mockPort;
        return serverAddress;

    }

    @Bean
    public GetVersionEndPoint getVersionEndPoint() {
        return new GetVersionEndPoint();
    }
Run Code Online (Sandbox Code Playgroud)

我用 @value 注释了 .properties 中的值,然后创建了一个用 …

java string nullpointerexception spring-boot

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

将证书导入到 cacerts,在 Mac OS Mojave 上出现文件 I/O 异常

您好,我正在尝试将证书导入到 Mac OSX Mojave 10.14.4 上的 cacerts 中。如果这有什么区别的话,我正在使用 OpenJDK。

我的证书文件是.p12。

这是我尝试走的路

keytool -import -alias nulogix -keystore $(/usr/libexec/java_home)/jre/lib/security/cacerts -file/Users/user/Desktop/cert.p12
Run Code Online (Sandbox Code Playgroud)

这给了我一个关键的工具错误

keytool error: java.io.FileNotFoundException: /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/jre/lib/security/cacerts (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

正确的道路是什么?

java terminal jvm keytool ssl-certificate

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

Spring Boot 终端中的 POST 请求不支持内容类型“text/plain”

我在 Spring Boot 中有一个应用程序。我创建了一个 post 请求来接受字符串并在文本文件中吐出 JSON。我使用 @RequestBody 作为地图。我不确定我是否正确使用了它,这就是我收到错误的原因?

当我尝试做的时候

curl -d "ncs|56-2629193|1972-03-28|20190218|77067|6208|3209440|self|-123|-123|-123|0.0|0.0|0.0|0.0|0.0|0.0|0.0"
 -H 'Content-Type: text/plain' 'http://localhost:9119/prediction'
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误

status":415,"error":"Unsupported Media Type","message":"Content type 'text/plain' not supported","path":"/prediction"
Run Code Online (Sandbox Code Playgroud)

这是我的控制器类

import java.io.IOException;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RestController
public class MockController {

    @Autowired
    MockEndPoint mockendpoint;
    @Autowired
    MockConfig mockconfig;

    String w;
    String x;
    String y;
    String z;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        return "hello!";
    }

    @RequestMapping(value …
Run Code Online (Sandbox Code Playgroud)

java post http hashmap spring-boot

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