小编Raf*_*ael的帖子

ClassNotFoundException被检查为异常的原因

ClassNotFoundException检查异常背后的原因是什么?

我一直在猜测和谷歌搜索试图理解为什么认为类没有被发现作为检查异常,因为我的所有想法告诉我它应该是未经检查的.

java exception classnotfoundexception

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

REST API错误消息应该国际化吗?

设计REST API的错误似乎是遵循标准HTTP代码(4XX和5XX)并包含正文(XML/JSON)的良好实践:

  • 简短的消息
  • 描述

我的问题是......这些信息应该国际化吗?

我倾向于认为向客户端显示消息是客户端负责,并且那些API错误应该被视为客户端应用程序和API之间的协议(格式和代码字段),但默认情况下不应被视为完全适合直接暴露给客户端,因此格式化最终消息"Ooops ...出错了"应在客户端完成.在其他情况下,我可以看到API部署,因为PO需要将"糟糕"更改为"Uups"等类似的东西,这看起来完全像是与客户端应用程序恕我直言的外观相关的东西.

rest error-handling internationalization

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

fileUsore类的getUsableSpace和getUnallocatedSpace之间有什么区别

我已经阅读了文档中的定义,并在互联网上进行了一些搜索,但我仍然不清楚.什么之间的区别getUsableSpace(),并getUnallocatedSpace()FileStore上课吗?

java nio

6
推荐指数
2
解决办法
880
查看次数

使用Java SE发布REST服务

我正在尝试使用Jersey和/或Java SE内置http服务器,使用JAX-RS 2.0和Java SE发布我的RESTful Web服务的简单方法.

我想将我的依赖关系保持在最低限度,所以我想避免灰熊,也不想使用任何外部应用程序服务器.

你能指点我如何发布有这个要求的休息服务吗?

提前致谢,

我的意思是实现这样的事情:

public static void main(String args[]) {
    try {
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer("http://localhost:8080/calculator/",new ResourceConfig(SumEndpoint.class));

        System.in.read();
        server.stop();

} catch (IOException ex) {
}
Run Code Online (Sandbox Code Playgroud)

}

......但避免了灰熊依赖

java rest

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

如何在 Spring-boot 2 中使用 Actuator 修改 prometheus 公开的指标名称

我在 springboot 2 中使用 Actuator 来公开 /actuator/prometheus 端点,prometheus 实例将从该端点提取指标。

\n\n

一切都很完美,除了因为我需要调整指标名称。我的意思不是对 Prometheus 有意义的后缀(_count、_total、_bucket,...),而是类似:

\n\n
\n

http_server_requests_seconds_count -> http_server_requests_count\n http_server_requests_seconds_max -> Latency_Seconds_Max\n http_server_requests_Seconds_sum -> Latency_Seconds_sum\n http_Server_requests_Seconds_Bucket -> Latency_Seconds_Bucket

\n
\n\n

对此有更好的方法吗?

\n\n

聚苯乙烯

\n\n

我知道我可以使用

\n\n
management.metrics.web.server.requests-metric-name=different\n
Run Code Online (Sandbox Code Playgroud)\n\n

要得到

\n\n
different_seconds_count\ndifferent_seconds_max \ndifferent_seconds_sum \ndifferent_seconds_bucket\n
Run Code Online (Sandbox Code Playgroud)\n\n

但很难:

\n\n

1\xc2\xba 去掉_seconds后缀

\n\n

2\xc2\xba 仅对其中之一使用不同的基本名称

\n\n

我猜我可以编写一个替代方案PrometheusRenameFilter,但不确定如何将其配置到默认注册表。

\n

spring-boot spring-boot-actuator prometheus

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

如何在ActiveMq嵌入式代理上启用Web控制台

我使用Spring 3.2.5 配置了一个ActiveMQ 5.8.0 嵌入式代理

这是我的jmsconfiguration.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <amq:broker brokerName="localhost" dataDirectory="./data" useJmx="true" persistent="true">
        <amq:persistenceAdapter>
            <amq:kahaDB directory="./kahadb" checksumJournalFiles="true" checkForCorruptJournalFiles="true" />
        </amq:persistenceAdapter>
        <amq:transportConnectors>
            <amq:transportConnector name="websocket" uri="ws://0.0.0.0:61614"/>
            <amq:transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
            <amq:transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
        </amq:transportConnectors>
    </amq:broker>

    <amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost" />
</beans>
Run Code Online (Sandbox Code Playgroud)

能够访问Web控制台是非常好的和有用的...但是我一直试图启用它而没有成功.

有谁知道如何配置它?

spring activemq-classic

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

Spring引导WAR大小与不同的嵌入式服务器

我正在使用spring-boot进行som实验,并且我意识到当我使用嵌入式Tomcat服务器时,生成的WAR大小比我使用Jetty甚至是具有相同其他依赖项的Undertow服务器时要小.

这怎么可能?...与tomcat相比,Undertow和Jetty应该是超轻型的.

尺码为:

Tomcat~18Mb

承诺~21Mb

码头~24Mb

它们中的任何一个对我来说都太大了,因为这是虚拟REST端点.这些是我的依赖:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-tomcat</artifactId> -->
        <!-- </dependency> -->
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-undertow</artifactId> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
<!--        <dependency> -->
<!--            <groupId>org.springframework.boot</groupId> -->
<!--            <artifactId>spring-boot-starter-test</artifactId> -->
<!--            <scope>test</scope> -->
<!--        </dependency> -->
    </dependencies>
Run Code Online (Sandbox Code Playgroud)

java tomcat embedded-jetty spring-boot undertow

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

调用start和run后的线程变量

我意识到这段代码:

public class TestThread3 extends Thread {

    private int i;
    public void run() {
         i++;
    }
    public static void main(String[] args) {
        TestThread3 a  = new TestThread3();
        a.run();
        System.out.println(a.i);
        a.start();
        System.out.println(a.i);
    }
}    
Run Code Online (Sandbox Code Playgroud)

结果1 1印刷...我不明白.我还没有找到有关如何解释这一点的信息.谢谢.

java multithreading

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

如何为类创建多个自定义JSON编组器

我需要有几个自定义JSON marshallers,因为我想以不同的方式为不同的目的进行编组.我知道如何使用以下方法设置自定义marshaller应用程序:

JSON.registerObjectMarshaller(MyClass) {
...
}  
Run Code Online (Sandbox Code Playgroud)

但这让我对这个特殊的定义感到困惑.

我怎样才能创建一个adhoc marshaller,比方说,只有一种方法?

grails json

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

在Spring Boot中监听存储库事件

我正在尝试RepositoryEventListener在春季启动应用程序中工作,但我想我做错了什么...

这是侦听器中的代码

@SuppressWarnings("rawtypes")
public class BeforeSaveEventListener extends AbstractRepositoryEventListener {  

    @Override
    public void onBeforeSave(Object customer) {
        throw new RuntimeException("++++ BEFORE SAVE EVENT ++++");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序类

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(Application.class);
        springApplication.addListeners(new BeforeSaveEventListener());
        springApplication.run(args);
    }
}
Run Code Online (Sandbox Code Playgroud)

在保存操作中,我可以看到触发了以下事件:

Current Event is org.springframework.data.rest.core.event.BeforeCreateEvent received!
Current Event is org.springframework.data.rest.core.event.AfterCreateEvent received!
Current Event is org.springframework.web.context.support.ServletRequestHandledEvent received!
Run Code Online (Sandbox Code Playgroud)

因此,没有看到“ BeforeSave”事件……也许是文档中不推荐使用的东西,或者spring-boot机制可能有所不同?

java spring-data-jpa spring-boot

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

按位运算符意外行为

有人可以解释这个java按位运算符的行为??

System.out.println(010 | 4); //  --> 12
System.out.println(10 | 4);  //  --> 14
Run Code Online (Sandbox Code Playgroud)

谢谢!

java bitwise-operators

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

在groovy中测试私有方法

在Java中,它非常扩展以强制使用包保护而不是私有,以便更容易测试方法.

现在我正在切换到Groovy,我注意到的第一件事就是公共默认访问修饰符,后来,受包保护不是很干净,并且在Groovy中很容易使用,就像在Java中一样.

然后我也意识到私有字段和私有方法不是私有"bug" - > http://jira.codehaus.org/browse/GROOVY-1875

...但是,当然,这是一个可能在某个时刻解决的错误所以我不会依赖于此(我会吗?)

那么......在groovy中测试受限制方法的首选方法是什么?

testing groovy

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