小编Fed*_*zza的帖子

为aspectj运行JDK8

我正在尝试使用JDK8运行aspectj-maven插件.但它给出的错误如"java.lang.CharSequence类型无法解析.它是从所需的.class文件间接引用的"

有关如何解决的任何帮助,或者aspectj-maven-plugin是否支持JDK8.我正在使用1.6版本的aspectj - maven-plugin.

java aspectj maven-plugin maven

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

顶级命中的ElasticSearch聚合

我有以下数据:

{"action":"CREATE","docs":1,"date":"2016 Jun 26 12:00:12","userid":"1234"}
{"action":"REPLACE","docs":2,"date":"2016 Jun 27 12:00:12","userid":"1234"}
{"action":"REPLACE","docs":1,"date":"2016 Jun 27 13:00:12","userid":"1234"}
{"action":"CREATE","docs":1,"date":"2016 Jun 28 12:00:12","userid":"3431"}
{"action":"REPLACE","docs":2,"date":"2016 Jun 28 13:00:12","userid":"3431"}
{"action":"CREATE","docs":1,"date":"2016 Jun 29 12:00:12","userid":"9999"}
Run Code Online (Sandbox Code Playgroud)

为了按日期(降序)获取每个唯一用户订单的记录,我使用了如下所示的Top Hits:

"aggs": {
  "user_bucket": {
    "terms": {
      "field": "userid"
    },
    "aggs": {
      "user_latest_count": {
        "top_hits": {
          "size": 1,
          "sort": [
            {
              "data": {
                "order": "desc"
              }
            }
          ],
          "_source": {
            "include": [
              "docs"
            ]
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

以上查询的结果如下:

{"action":"REPLACE","docs":1,"date":"2016 Jun 27 13:00:12","userid":"1234"}
{"action":"REPLACE","docs":2,"date":"2016 Jun 28 13:00:12","userid":"3431"}
{"action":"CREATE","docs":1,"date":"2016 Jun 29 12:00:12","userid":"9999"}
Run Code Online (Sandbox Code Playgroud)

现在,我想进一步聚合这个,结果如下: …

elasticsearch

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

Spring分别缓存列表中的所有元素

我试图将缓存添加到CRUD应用程序,我开始执行以下操作:

@Cacheable("users")
List<User> list() {
    return userRepository.findAll()
}
@CachePut(value = "users", key = "#user.id") 
void create(User user) {
    userRepository.create(user)
}
@CachePut(value = "users", key = "#user.id") 
void update(User user) {
    userRepository.update(user)
}
@CacheEvict(value = "users", key = "#user.id") 
void delete(User user) {
    userRepository.delete(user)
}
Run Code Online (Sandbox Code Playgroud)

我的问题是我希望create / update / delete操作可以为该操作更新已存储在缓存中的元素list()(请注意,list()不是从数据库中拉出而是从数据引擎中拉出),但是我无法做到这一点。

我想缓存list()单独返回的所有元素,以便所有其他操作可以使用来更新缓存#user.id。或者,可能需要执行所有操作来更新已存储在缓存中的列表。

我读到我可以在更新整个缓存时逐出整个缓存,但是我想避免这样的事情:

@CacheEvict(value = "users", allEntries=true) 
void create(User user) {
    userRepository.create(user)
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以在缓存的集合中创建/更新/删除值?还是将集合中的所有值作为单独的键缓存?

java spring caching spring-boot spring-cache

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

由于maven-surefire-plugin与VM崩溃,GitLab CI失败

我们有大约10个不同的应用程序,它们是使用Groovy的Spring Boot项目.

我们所有的项目都在所有开发人员工作站中正确构建,并且它们正常运行直到昨天,但突然所有项目今天仅在我们的GitLab CI管道中停止工作且出现以下错误:

[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:37 min
[INFO] Finished at: 2018-10-31T17:49:11Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project ctg-oms-component: There are test failures.
[ERROR] 
[ERROR] Please refer to /builds/ctg-integrations/ctg-oms-component/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] ExecutionException The forked VM terminated without properly saying …
Run Code Online (Sandbox Code Playgroud)

maven-surefire-plugin gitlab docker spring-boot gitlab-ci

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

在 Catalina 中创建根符号链接的正确方法是什么

我需要通过在 中放置一个目录来复制我们的生产环境/reports/2019/,正如您所知,这在 Catalina 中不再可能(至少在不禁用 SIP 的情况下)。

这样做实际上是在禁用安全性,但我想有一种正确的方法可以做到这一点。

/reports没有办法在不禁用 SIP 或不影响安全性的情况下创建一个链接到读写卷的符号链接?

macos macos-catalina

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

为什么没有为Jersey控制器检测到我的Aspect(使用自定义注释)?

我想在Jersey控制器上创建一个Aspect来衡量服务执行的时间.我正在反对我的切入点,因为它没有被检测到,我的方面永远不会被启动.

我尝试过使用许多切入点,例如:

execution(@Monitor * *.*(..))
execution(public * *(..))
change the order of @Aspect and @Component

Added a pointcut like this:
@Pointcut("execution(@Monitor * *.*(..))")
public void monitorRequestTargets(){}
@Around("monitorRequestTargets()")

Tried using AOP and CGLIB
<aop:aspectj-autoproxy proxy-target-class="true"/>

Also tried changing the order of configuration in context.xml
Run Code Online (Sandbox Code Playgroud)

Eclipse检测到我的方法正在建议我的方法,但它不会在运行时执行.你能否给我一些提示,说明为什么没有创建方面或切入点没有启动?

我的代码如下.

的context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <!-- Enables the Spring MVC @Controller -->
    <annotation-driven />

    <!-- Enables AspectJ -->
    <aop:aspectj-autoproxy />

    <!-- .....more …
Run Code Online (Sandbox Code Playgroud)

java aop aspectj jersey spring-aop

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

SpringBoot测试中如何获取正在运行的服务器端口?

我正在使用 Spock 作为测试框架,使用 Apache Camel 路由为 Spring Boot 应用程序创建一些单元测试,并且我需要模拟来自另一个应用程序的响应。我为此制作了一个模拟控制器,但我需要将测试运行的端口注入到属性中。有没有办法获取正在运行测试的端口?

\n\n

我尝试过

\n\n
@LocalServerPort\nprivate int port \n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n
@Autowired Environment environment;\nString port = environment.getProperty("local.server.port");\n
Run Code Online (Sandbox Code Playgroud)\n\n

但两者都返回 -1,我不知道\xc2\xb4t 是否有其他方法来获取端口

\n\n

我的测试配置了以下注释:

\n\n
@RunWith(SpringRunner)\n@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)\n@ActiveProfiles(\'test\')\n
Run Code Online (Sandbox Code Playgroud)\n\n

另外,有没有办法在文件中注入随机端口application-test.yml?理想情况下,我需要在我的application-test.yml文件中执行类似的操作:

\n\n
app:\n  service: localhost:${server.port}\n
Run Code Online (Sandbox Code Playgroud)\n\n

其中端口是运行测试的随机端口。

\n

java spring spring-boot

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

有没有办法让弹性搜索在聚合期间返回每个生成的桶的命中?

现在我有这样的查询:

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "uuid": "xxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxxx"
                    }
                },
                {
                    "range": {
                        "date": {
                            "from": "now-12h",
                            "to": "now"
                        }
                    }
                }
            ]
        }
    },
    "aggs": {
        "query": {
            "terms": [
                {
                    "field": "query",
                    "size": 3
                }
            ]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

聚合效果非常好,但我似乎无法找到一种方法来控制返回的命中数据,我可以使用dsl顶部的size参数,但返回的命中不会返回以桶为单位,因此桶结果不符合命中结果.有没有办法纠正这个问题,还是我必须发出2个单独的查询?

aggregation elasticsearch

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

如何在后向正则表达式中使用限定符(* 或 +)?

我正在学习具有环视(lookbehind 和lookahead)功能的正则表达式,但我不能在lookbehind 中使用.*.+量词(但我可以使用lookahead)。

我试图修复的正则表达式如下:

(?<!yellow.*)blue(?=.*brown)
Run Code Online (Sandbox Code Playgroud)

这个想法是匹配那些没有yellowblue只有brown在蓝色之后存在的线。以下是一些示例:

yellow blue brown                    // shouldn't match
f blue brown                         // should match
sdff blue brown                      // should match
asdf  f blue c                       // shouldn't match
yellow blue fblue b f brown          // shouldn't match
Run Code Online (Sandbox Code Playgroud)

这是我的测试:

http://regex101.com/r/fY4kI9/5

我得到的错误是:

。* Lookbehinds 必须是零宽度,因此不允许使用量词

你知道我该如何解决这个问题吗?

java regex

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

Spring Boot 不使用@ControllerAdvice 覆盖异常

我想从控制器建议方面抛出一个标准的自定义异常,但由于某种原因,我的自定义异常没有被 Spring Boot (1.3.3-RELEASE) 捕获。

这是我的代码:

我的测试

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(MyApplication.class)
@WebIntegrationTest("server.port:9000") 
public class ControllerTest {
    private final String URL = "http://localhost:9000";

    @Test
    public void testCustomExceptionResponse() {
        // Invoke my controller generating some exception
        Map error = restTemplate.getForObject(URL+"/exception/", Map.class);
        assertTrue(error.get("exception").contains("MyCustomException"));
    }
}
Run Code Online (Sandbox Code Playgroud)

控制器

@RequestMapping(value = "/", method = RequestMethod.GET)
public List<Object> findAll() throws Exception {
    // generate whatever exception here
    if (1<2) throw new IllegalIdentifierException("test whatever exception");
    return ccRepository.findByActive(true);
}
Run Code Online (Sandbox Code Playgroud)

使用 @ControllerAdvice 注释的 GlobalExceptionHandler

@ControllerAdvice
public class GlobalExceptionHandler {
    private static final …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-boot

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