当我尝试运行spring boot应用程序时出现以下错误.
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: oracle.jdbc.OracleDriver
Origin: "driverClassName" from property source "source"
Reason: Unable to set value for property driver-class-name
Action:
Update your application's configuration
Run Code Online (Sandbox Code Playgroud)
这是同样的问题,但我没有使用maven.
我正在使用spring Boot 2.0.0以下的首发.
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
testCompile "org.springframework.boot:spring-boot-starter-test"
}
Run Code Online (Sandbox Code Playgroud)
这是我的application.properties档案
spring.datasource.url= *****
spring.datasource.username= ******
spring.datasource.password= ******
Run Code Online (Sandbox Code Playgroud) 我正在尝试测试我的春季休假客户,但遇到了麻烦。这是我的客户课程:
@Component
public class MyClient{
private RestTemplate restTemplate;
@Autowired
public MyClient(RestTemplateBuilder restTemplateBuilder,ResponseErrorHandler myResponseErrorHandler) {
this.restTemplate = restTemplateBuilder
.errorHandler(myResponseErrorHandler)
.build();
}
//other codes here
}
Run Code Online (Sandbox Code Playgroud)
这myResponseErrorHandler 是重写类的类 handleError和hasError方法ResponseErrorHandler。
现在我的测试课是
@RunWith(SpringRunner.class)
public class MyClientTest {
@InjectMocks
MyClient myClient;
@Mock
RestTemplate restTemplate;
@Mock
RestTemplateBuilder restTemplateBuilder;
//test cases here
}
Run Code Online (Sandbox Code Playgroud)
但是出现以下错误,并且不确定如何解决。
You haven't provided the instance at field declaration so I tried to construct the instance.
However the constructor or the initialization block threw an exception : null
Run Code Online (Sandbox Code Playgroud) 我正在使用Egitwitheclipse来处理我的 java 项目。我创建了一个从 master 调用的分支branch1并开始研究它。
与此同时,我的同事branch2从 master 创建了另一个分支,进行了一些更改并合并branch2回 master。
现在我需要将 master 上所做的所有更改转移到我的分支上branch1。
我如何使用eclipse或github不使用任何命令来实现此目的。
我正在使用RestTemplate从远程休息服务获取数据,我的代码是这样的。
ResponseEntity<List<MyObject >> responseEntity = restTemplate.exchange(request, responseType);
Run Code Online (Sandbox Code Playgroud)
但是,如果没有结果,休息服务将仅返回短信,说明未找到记录,并且我上面的代码行将引发异常。我可以首先将结果映射到字符串,然后用于Jackson 2 ObjectMapper映射到MyObject.
ResponseEntity<String> responseEntity = restTemplate.exchange(request, responseType);
String jsonInput= response.getBody();
List<MyObject> myObjects = objectMapper.readValue(jsonInput, new TypeReference<List<MyObject>>(){});
Run Code Online (Sandbox Code Playgroud)
但我不喜欢这种方法。对此有没有更好的解决方案。
我有一个控制器,用于RestTemplate从多个休息端点获取数据。由于RestTemplate阻塞,我的网页需要很长时间才能加载。为了提高性能,我计划将所有用法替换RestTemplate为WebClient. 我目前使用的方法之一RestTemplate如下。
public List<MyObject> getMyObject(String input){
URI uri = UriComponentsBuilder.fromUriString("/someurl")
.path("123456")
.build()
.toUri();
RequestEntity<?> request = RequestEntity.get(uri).build();
ParameterizedTypeReference<List<MyObject>> responseType = new ParameterizedTypeReference<List<MyObject>>() {};
ResponseEntity<List<MyObject>> responseEntity = restTemplate.exchange(request, responseType);
MyObject obj = responseEntity.getBody();
}
Run Code Online (Sandbox Code Playgroud)
现在我想替换上面的方法来使用,WebClient但我是新手WebClient,不知道从哪里开始。任何指导和帮助表示赞赏。
我看到一些其他服务返回如下响应
MappingJacksonValue result= new MappingJacksonValue(resultPojo);
return ResponseEntity.status(HttpStatus.OK).body(result);
Run Code Online (Sandbox Code Playgroud)
和错误
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new MappingJacksonValue("Error Message..."));
Run Code Online (Sandbox Code Playgroud)
MappingJacksonValue如果我们可以简单地执行以下操作,那么将对象包裹在里面有什么用
return ResponseEntity.status(HttpStatus.OK).body(resultPojo);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Error Message...");
Run Code Online (Sandbox Code Playgroud)
我看到我们可以通过 using 来使用过滤器选项MappingJacksonValue,但是如果我们不使用它,那么使用MappingJacksonValue.
笔记
我正在使用Spring boot.
我找不到这两者之间的区别。这些是相同还是不同。
我肯定我会得到很多反对票,也许会被搁置。但是我找不到我的问题的确切答案。