我正在尝试运行Google Api Vision示例代码,但我收到此错误:
线程"main"中的异常java.lang.NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
这些是我项目的特点:
1-POM.xml文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.multiedro</groupId>
<artifactId>vision</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>API Vision</name>
<description>Estudando a api vision</description>
<dependencies>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>0.18.0-beta</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
2-级
package br.com.visio;
// Imports the Google Cloud client library
import com.google.cloud.vision.spi.v1.ImageAnnotatorClient;
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.EntityAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Feature.Type;
import com.google.cloud.vision.v1.Image;
import com.google.protobuf.ByteString;
import java.nio.file.Files;
import …Run Code Online (Sandbox Code Playgroud) 我无法确定是否可以读取 pom.xml 文件中 Spring 的 application.properties 中的任何数据。
在我的application-dev.properties文件中,我有一个属性:
google.project.id = 123456789
Run Code Online (Sandbox Code Playgroud)
在我的application-test.properties文件中,我有一个属性:
google.project.id = 987654321
Run Code Online (Sandbox Code Playgroud)
在我的application.properties文件中,我有一个属性。有一次我将其设置为DEV,另一次设置为TEST:
spring.profiles.active=dev
Run Code Online (Sandbox Code Playgroud)
在我的pom.xml文件中,我想根据 spring.profiles.active 属性中的配置读取此项目 id:
<configuration>
<projectId> PROJECT ID ???</projectId>
<version>1</version>
</configuration>
Run Code Online (Sandbox Code Playgroud)
请问有人可以帮助我吗?
谢谢。
我有两类测试:1- 用于控制器类的单元测试和 2- 用于服务类的单元测试,如下所示:
1-测试类控制器:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class CentroDeCustoRestControllerTeste {
@Autowired
private MockMvc mvc;
@MockBean
private CentroDeCustoService service;
@Test
@WithMockUser(username = "teste-app@teste.com", authorities = {"ADMIN"})
public void aoBuscarUmCentroDeCustoRetornarUmJsonComPropriedadeCentroDeCusto() throws Exception {
CentroDeCusto centroDeCusto = new CentroDeCusto();
centroDeCusto.setNome("Financeiro");
given(service.centroDeCusto(1L)).willReturn(Optional.of(centroDeCusto));
mvc.perform(get("/centrosdecustos/1").contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.centroDeCusto", org.hamcrest.core.Is.is(centroDeCusto.getCentroDeCusto())));
}
}
Run Code Online (Sandbox Code Playgroud)
2- 测试类服务:
@RunWith(SpringRunner.class)
public class CentroDeCustoServiceImplTeste {
@TestConfiguration
static class CentroDeCustoServiceImplConfiguracaoContexto {
@Bean
public CentroDeCustoService centroDeCustoService() {
return new CentroDeCustoServiceImpl();
}
}
@Autowired
private CentroDeCustoService service;
@MockBean
private CentroDeCustoRepository repository;
@Before
public void setup() …Run Code Online (Sandbox Code Playgroud) 我正在尝试对来自控制器的调用执行单元测试,但收到NullPointerException。回调返回一个ResponseEntity <Page>对象,如下所示:
@GetMapping
public ResponseEntity<Page<CentroDeCusto>> centrosDeCustos(Pageable paginacao) {
Page<CentroDeCusto> centrosDeCustos = centroDeCustoRepository.departamentosPorDataDeAtualizacao(paginacao);
if (centrosDeCustos.hasContent())
return new ResponseEntity<>(centrosDeCustos, HttpStatus.OK);
else
return new ResponseEntity<>(centrosDeCustos, HttpStatus.NOT_FOUND);
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class CentroDeCustoRestControllerTeste {
@Autowired
private MockMvc mvc;
@MockBean
private CentroDeCustoRepository repository;
@Test
@WithMockUser(username = "teste-app-@teste.com", authorities = {"ADMIN"})
public void aoBuscarCentrosDeCustoRetornarUmaListaComVariosCentrosDeCusto() throws Exception {
PageRequest paginacao = PageRequest.of(1, 10);
List<CentroDeCusto> centrosDeCustos = Arrays.asList(new CentroDeCusto(), new CentroDeCusto());
Page<CentroDeCusto> centrosDeCustosPage = new PageImpl<>(centrosDeCustos, paginacao, centrosDeCustos.size());
given(repository.departamentosPorDataDeAtualizacao(paginacao)).willReturn(centrosDeCustosPage);
mvc.perform(get("/centrosdecustos").contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
} …Run Code Online (Sandbox Code Playgroud) java ×4
spring-boot ×3
spring ×2
unit-testing ×2
api ×1
maven ×1
spring-mvc ×1
spring-test ×1
vision ×1