这是我的码头工人形象。我想从最后提到的 docker run 命令中传递的任何内容覆盖下面设置的默认环境变量
FROM ubuntu:16.04
ADD http://www.nic.funet.fi/pub/mirrors/apache.org/tomcat/tomcat-8/v8.0.48/bin/apache-tomcat-8.0.48.tar.gz /usr/local/
RUN cd /usr/local && tar -zxvf apache-tomcat-8.0.48.tar.gz && rm apache-tomcat-8.0.48.tar.gz
RUN mv /usr/local/apache-tomcat-8.0.48 /usr/local/tomcat
RUN rm -rf /usr/local/tomcat/webapps/*
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV CATALINA_HOME /usr/local/tomcat
ENV CATALINA_BASE /usr/local/tomcat
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
ENV dummy_url defaulturl
ENV database databasedefault
COPY my.war /usr/local/tomcat/webapps/
RUN echo >> /usr/local/tomcat/conf/test.properties
RUN echo dummy_url =$dummy_url >> /usr/local/tomcat/conf/test.properties
RUN echo database =$database >> /usr/local/tomcat/conf/test.properties
ENTRYPOINT ["catalina.sh", "run"]
Run Code Online (Sandbox Code Playgroud)
在本地运行:
docker run -p 8080:8080 -e dummy_url=http:google.com -e database=jdbc://mysql allimages/myimage:latest
Run Code Online (Sandbox Code Playgroud)
dummy_url 和数据库似乎没有在我添加它们的文件中被覆盖 - …
我正在尝试对 QueryDSL 使用分页 - 使用 com.mysema.querydsl 包。
我所有的 Querydsl 查询类型都如下所示 -
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QCountry extends EntityPathBase<Country> {...}
Run Code Online (Sandbox Code Playgroud)
目前,我的存储库实现类看起来像这样 -
@Override
public Page<Country> findPaginatedCountries(String country, Optional<String> status, Pageable pageable) {
QCountry qCountry= QCountry.someObject;
QActiveCountry qActiveCountry = QActiveCountry.activeCountry;
JPAQuery jpaQuery = new JPAQuery(entityManager);
QueryBase queryBase = jpaQuery.from(qCountry).innerJoin(qActiveCountry).fetch()
.where(qCountry.codeLeft.country.upper().eq(country.toUpperCase()))
.where(qCountry.codeRight.country.upper().eq(country.toUpperCase()));
if(status.isPresent()){
queryBase = queryBase.where(qActiveCountry.id(qCountry.active.id))
.where(qActiveCountry.status.upper().eq(status.get().toUpperCase()));
}
.......}
Run Code Online (Sandbox Code Playgroud)
现在,我希望这个动态查询返回一个分页响应。我想使用 Spring 的分页来做到这一点,而不是手动设置偏移量、大小等。
我知道我可以使用 QueryDslRepositorySupport 类 - 在这里实现 - https://github.com/keke77/spring-data-jpa-sample/blob/master/spring-data-jpa/src/main/java/com/gmind7/面包店/员工/EmployeeRepositoryImpl.java
来自上述链接的示例代码 -
@Override
public Page<Employees> QFindByOfficeCode(long officeCode, Pageable pageable) {
//JPAQuery query = new JPAQuery(em); …Run Code Online (Sandbox Code Playgroud) 当你想使用 postgres 的 SELECT FOR UPDATE SKIP LOCKED 功能来确保两个不同的用户从一个表中读取并声明任务不会被彼此阻止并且也不会被另一个用户读取任务时:
查询中正在使用连接来检索任务。除了包含主要信息的表之外,我们不希望任何其他表具有行级锁定。下面的示例查询 - 仅锁定表中的行 - 以下查询中的“任务”
SELECT v.someid , v.info, v.parentinfo_id, v.stage FROM task v, parentinfo pi WHERE v.stage = 'READY_TASK'
AND v.parentinfo_id = pi.id
AND pi.important_info_number = (
SELECT MAX(important_info_number) FROM parentinfo )
ORDER BY v.id limit 200 for update skip locked;
Run Code Online (Sandbox Code Playgroud)
现在,如果用户 A 正在检索该表的大约 200 行,用户 B 应该能够检索另一组 200 行。
编辑:根据下面的评论,查询将更改为:
SELECT v.someid , v.info, v.parentinfo_id, v.stage FROM task v, parentinfo pi WHERE v.stage = 'READY_TASK'
AND v.parentinfo_id = pi.id …Run Code Online (Sandbox Code Playgroud) 这是我的 protoc jar 插件 -
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>${protoc-maven-plugin.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>${protobuf.version}</protocVersion>
<includeStdTypes>true</includeStdTypes>
<includeDirectories>
<include>src/main/resources</include>
</includeDirectories>
<inputDirectories>
<include>src/main/resources</include>
</inputDirectories>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我想包含一些来自 nexus 上可用的 Maven 存储库的导入语句 - 其中包含一堆 proto 文件及其 java 编译版本。它是一个包含原始文件的 jar。
如何将这些 proto 文件(打包在 jar 中)包含在 protoc 路径中,以便可以将 proto 文件导入到我当前的工作目录中?
问题是,当我 mavenize 我的项目时,导入始终失败 - 找不到 .proto 文件。
我的 proto 命令用作协议的一部分,看起来像 - protoc-jar: 执行: [C:\protocjar3624070738032398618\bin\protoc.exe, -IC:\protocjar3624070738032398618\include, -IC:myproject\src\main\resources , --java_out=C:\myproject\target\ generated-sources, C:\myproject\somedummy.proto]
该命令无法访问我正在导入的 jar 的 com.custom.proto 包,并且我不确定要添加到上述配置中的 inputDirectories 设置中才能将此包包含在 protoc 命令中。
PS 我可以使用此设置 …
参考官方文档中提到的建立亲子关系的例子——https: //www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html
该链接提供了问答连接关系,其中问题是父类型,答案是子类型。
如果您需要在一个查询中搜索匹配某些文本的所有父母以及他们的孩子匹配某些特定于孩子的文本,您会怎么做?
假设他们在 json 文档中有键值对,如下所示,我们搜索与问题中的文本匹配的父项和与 answer-text 中的值匹配的子项。
Parent --> question --> "question-text" : "Geography: Where is Mt. Everest?"
Child --> answer --> "answer-text" : "Nepal?"
Run Code Online (Sandbox Code Playgroud)
我们不希望结果中只包含父项或子项,而是所有父项及其与查询匹配的关联子项。
我知道内部命中是一种选择,但无法弄清楚用法 - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html
我希望问题很清楚,如果需要可以添加更多细节。
我还尝试了此处提到的父子内部命中示例:
例子:
POST test_index/_search
{
"query": {
"has_child": {
"type": "child",
"query": {
"match": {
"number": 2
}
},
"inner_hits": {}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我所有父母的匹配孩子。如何向父级添加过滤器并仅查询同一查询中的特定父级(以及子级过滤器)?是否可以在同一查询中的特定字段上过滤父记录?
像这样的东西——
POST test_index/_search
{
"query": {
<match parents first on number:1 and then match the children below>
"has_child": {
"type": "child",
"query": { …Run Code Online (Sandbox Code Playgroud) 我的服务类如下,其后是测试 -
@Service
public class MyServiceImpl implements MyService {
@Autowired
private RestTemplate restTemplate;
@Override
public StudentInfo getStudentInfo(String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
HttpEntity entity = new HttpEntity(headers);
StudentInfo student = null;
URI uri = new URI("http:\\someurl.com");
ResponseEntity<String> responseEntity = restTemplate.exchange(uri,
HttpMethod.GET, entity,
String.class);
if (responseEntity.getStatusCode().equals(HttpStatus.NO_CONTENT)) {
throw new Exception("Student absent");
}else {
ObjectMapper mapper = new ObjectMapper();
StudentInfo student = mapper.readValue(responseEntity.getBody(), StudentInfo.class);
}
return student;
}
}
Run Code Online (Sandbox Code Playgroud)
测试类:在我下面的测试类中,我看到ResponseEntity对象在调试时为null,导致NPE.
@RunWith(MockitoJUnitRunner.class)
public class MyServiceImplTest {
@InjectMocks
private MyService …Run Code Online (Sandbox Code Playgroud) 我使用 vpc 端点进行弹性搜索,并使用 RestHighLevelClient 为我的文档建立索引。
我正在使用 java High Level Rest Client v6.2.2 连接 Elasticsearch 版本 6.0
我无需任何身份验证即可访问我的集群端点 - https://vpc......us-east-1.es.amazonaws.com
代码如下:
RestHighLevelClient client = null;
try {
Header[] headers = { new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")};
RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost("https://vpc...us-east-1.es.amazonaws.com", 9200, "https"));
restClientBuilder.setMaxRetryTimeoutMillis(30); //Currently, set as default
restClientBuilder.setDefaultHeaders(headers);
client = new RestHighLevelClient(restClientBuilder);
IndexRequest indexRequest = new IndexRequest(index, "doc", 1)
.source(documentJson, XContentType.JSON);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
IndexResponse indexResponse = client.index(indexRequest);
}catch(Exception e){
}finally {
try {
client.close();
} catch (IOException e) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
例外: …
docker ×1
dockerfile ×1
junit ×1
mockito ×1
pagination ×1
postgresql ×1
protoc ×1
querydsl ×1
spring ×1
spring-boot ×1
spring-test ×1