小编Mat*_*W90的帖子

Spring AOP - 如果没有 xml 配置,方面将无法工作

我的目的是在服务中获取消息方法之前运行方面。我不想使用 xml 配置,所以我添加(希望)必要的注释。但是,当我运行我的应用程序时,aspect 不起作用,什么也没有发生。你能解释一下为什么吗?

服务

public interface Service {
  void getMessage();
}
Run Code Online (Sandbox Code Playgroud)

服务实现

import org.springframework.stereotype.Component;

@Service
public class ServiceImpl implements Service {
  public void getMessage() {
    System.out.println("Hello world");
  }
}
Run Code Online (Sandbox Code Playgroud)

方面

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class LoggingAspect {

    @Before("execution(* com.example.aop.Service.getMessage())")
    public void logBefore(JoinPoint joinPoint) {
        System.out.println("AOP is working!!!");
    }
}
Run Code Online (Sandbox Code Playgroud)

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass=true)
@ComponentScan("com.example")
public class AopApplication {

    public static void main(String[] args) {
        final ConfigurableApplicationContext …
Run Code Online (Sandbox Code Playgroud)

java spring-aop spring-boot

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

“path”参数必须是字符串类型。接收到的类型对象 - Angular 7

我尝试在我的角度项目打字上运行测试

ng test --browsers=PhantomJS
Run Code Online (Sandbox Code Playgroud)

之前,我必须使用命令手动安装 phantomjs

npm install phantomjs-prebuilt@2.1.16 -ignore-scripts
Run Code Online (Sandbox Code Playgroud)

但是当ng test --br ...我收到这个错误后

23 05 2019 08:08:28.194:错误 [配置]: 配置文件中的错误!类型错误 [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。在 phantomJSExePath (/gui-build/node_modules/karma-phantomjs-launcher/index.js:18) 处的 Object.extname (path.js:1365:5) 处的 validateString (internal/validators.js:125:11) 处接收到类型对象:12)在对象。(/gui-build/node_modules/karma-phantomjs-launcher/index.js:107:12) 在 Module._compile (internal/modules/cjs/loader.js:701:30) 在 Object.Module._extensions..js (内部/模块/cjs/loader.js:712:10)在Module.load(内部/模块/cjs/loader.js:600:32)在tryModuleLoad(内部/模块/cjs/loader.js:539:12) )在Function.Module._load(内部/模块/cjs/loader.js:531:3)在Module.require(内部/模块/cjs/loader.js:637:17)在要求(内部/模块/cjs/ helpers.js:22:18)....

我怎样才能解决这个问题?

环境:Angular CLI:7.3.9 节点:10.15.3 操作系统:linux x64 Angular:7.2.15

karma.conf.js

 // Karma configuration
 // Generated on Wed Oct 24 2018 11:15:29 GMT+0200 (Central European Daylight Time)
 const path = require('path');

 module.exports = function(config) {
 config.set({
 files: [
  'src/**/*.js',
  'src/test/**/*.js'
 ],
 basePath: '', …
Run Code Online (Sandbox Code Playgroud)

node.js npm phantomjs angular

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

当 prometheus 端点调用时 MockMvc 收到 404

我想使用MockMvc类测试 Prometheus 指标端点。

一切正常,但昨天我将项目迁移到Java 15,SpringBoot 2.4.3SpringCloud 2020.0.1. 现在,只有普罗米修斯测试不起作用,我收到404而不是预期的200。我对build.gradleeq:有所有必要的依赖runtime("io.micrometer:micrometer-registry-prometheus")。在application-test.yml我有一个禁用安全配置,合同测试协议代理端点等。

我的测试:

@ExtendWith({SpringExtension.class, PostgresSpringDataSourceExtension.class})
@ActiveProfiles({"test"})
@SpringBootTest
@AutoConfigureMockMvc
public class PrometheusEndpointTest {

 @Autowired private MockMvc mockMvc;

 @Test
 public void metricsThroughPrometheusEndpoint() throws Exception {
  MvcResult result = 
  this.mockMvc.perform(get("/metrics")).andExpect(status().isOk()).andReturn();
 }
}
Run Code Online (Sandbox Code Playgroud)

部分application.yaml配置:

management:
  endpoint:
    prometheus:
      enabled: true
  endpoints:
    enabled-by-default: false
    web:
      exposure:
        include: 'prometheus'
      base-path: '/'
      path-mapping:
        prometheus: 'metrics'
Run Code Online (Sandbox Code Playgroud)

java spring-boot prometheus

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

在 Java 11 中使用 mockito 时找不到序列化程序

我使用 mockito 为我的控制器和服务创建了一个测试。虽然我使用 java 8 一切正常,但在迁移到 Java 11 后,出现此错误。也许有人可以帮我解决这个测试?

public class ConfigurationControllerTest {

    @Mock
    private ConfigurationService configurationService;

    @InjectMocks
    private ConfigurationController controller;

    private MockMvc mockMvc;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mockMvc = MockMvcBuilders
                .standaloneSetup(controller)
                .build();
    }

    @Test
    public void find() throws Exception {
        //given
        final ConfigurationsDto configDto = mock(ConfigurationsDto.class);
        given(configurationService.find(any())).willReturn(Arrays.asList(configDto));


        //when and then
        mockMvc
                .perform(get("/config/1.0.0/")
                        .accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk());
    }
}
Run Code Online (Sandbox Code Playgroud)

运行后,我收到了 https 状态 500 和错误:

[main] ERROR app.controllers.global.AdviceController - 没有找到类 org.mockito.internal.debugging.LocationImpl 的序列化器,也没有发现创建 BeanSerializer 的属性(为了避免异常,禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过参考链:java. util.Collections$SingletonList[0]->app.dtos.ConfigurationsDto$MockitoMock$534475338["mockitoInterceptor"]->org.mockito.internal.creation.bytebuddy.MockMethodInterceptor["mockHandler"]->org.mockito.in .InvocationNotifierHandler["invocationContainer"]->org.mockito.internal.stubbing.InvocationContainerImpl["invocationForStubbing"]->org.mockito.internal.invocation.InvocationMatcher["invocation"]->org.mockito.internal.invocation.InterceptedInvocation [“地点”])

当然,我在 pom 中添加了所需的依赖项: …

java mockito java-11

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

Java 8 - 字符串流不同 - IllegalStateException

我有不同的上行动问题streamString的。

Stream<String> names = Arrays.asList("NAME A", "NAME B", "NAME A").stream();
names.distinct();
System.out.println(names.collect(Collectors.joining(",")));
Run Code Online (Sandbox Code Playgroud)

然后,我收到异常:

Exception in thread "main" java.lang.IllegalStateException: stream has already been operated upon or closed
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:229)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.Test.main(Test.java:62)
Run Code Online (Sandbox Code Playgroud)

但是如果我这样写这部分代码:

Stream<String> names = Arrays.asList("NAME A", "NAME B", "NAME A").stream();
final Stream<String> distinct = names.distinct();
System.out.println(distinct.collect(Collectors.joining(",")));
Run Code Online (Sandbox Code Playgroud)

一切都好。

独特的文档说:

Stream distinct() 返回由该流的不同元素(根据 Object.equals(Object))组成的流。对于有序流,不同元素的选择是稳定的(对于重复元素,保留遇到顺序中最先出现的元素。)对于无序流,没有稳定性保证。这是一个有状态的中间操作。

我做错了什么?

感谢帮助

java java-8 java-stream

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