ClassNotFoundException检查异常背后的原因是什么?
我一直在猜测和谷歌搜索试图理解为什么认为类没有被发现作为检查异常,因为我的所有想法告诉我它应该是未经检查的.
设计REST API的错误似乎是遵循标准HTTP代码(4XX和5XX)并包含正文(XML/JSON)的良好实践:
我的问题是......这些信息应该国际化吗?
我倾向于认为向客户端显示消息是客户端负责,并且那些API错误应该被视为客户端应用程序和API之间的协议(格式和代码字段),但默认情况下不应被视为完全适合直接暴露给客户端,因此格式化最终消息"Ooops ...出错了"应在客户端完成.在其他情况下,我可以看到API部署,因为PO需要将"糟糕"更改为"Uups"等类似的东西,这看起来完全像是与客户端应用程序恕我直言的外观相关的东西.
我已经阅读了文档中的定义,并在互联网上进行了一些搜索,但我仍然不清楚.什么之间的区别getUsableSpace(),并getUnallocatedSpace()在FileStore上课吗?
我正在尝试使用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)
}
......但避免了灰熊依赖
我在 springboot 2 中使用 Actuator 来公开 /actuator/prometheus 端点,prometheus 实例将从该端点提取指标。
\n\n一切都很完美,除了因为我需要调整指标名称。我的意思不是对 Prometheus 有意义的后缀(_count、_total、_bucket,...),而是类似:
\n\n\n\n\nhttp_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\nmanagement.metrics.web.server.requests-metric-name=different\nRun Code Online (Sandbox Code Playgroud)\n\n要得到
\n\ndifferent_seconds_count\ndifferent_seconds_max \ndifferent_seconds_sum \ndifferent_seconds_bucket\nRun Code Online (Sandbox Code Playgroud)\n\n但很难:
\n\n1\xc2\xba 去掉_seconds后缀
\n\n2\xc2\xba 仅对其中之一使用不同的基本名称
\n\n我猜我可以编写一个替代方案PrometheusRenameFilter,但不确定如何将其配置到默认注册表。
我使用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-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) 我意识到这段代码:
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印刷...我不明白.我还没有找到有关如何解释这一点的信息.谢谢.
我需要有几个自定义JSON marshallers,因为我想以不同的方式为不同的目的进行编组.我知道如何使用以下方法设置自定义marshaller应用程序:
JSON.registerObjectMarshaller(MyClass) {
...
}
Run Code Online (Sandbox Code Playgroud)
但这让我对这个特殊的定义感到困惑.
我怎样才能创建一个adhoc marshaller,比方说,只有一种方法?
我正在尝试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按位运算符的行为??
System.out.println(010 | 4); // --> 12
System.out.println(10 | 4); // --> 14
Run Code Online (Sandbox Code Playgroud)
谢谢!
在Java中,它非常扩展以强制使用包保护而不是私有,以便更容易测试方法.
现在我正在切换到Groovy,我注意到的第一件事就是公共默认访问修饰符,后来,受包保护不是很干净,并且在Groovy中很容易使用,就像在Java中一样.
然后我也意识到私有字段和私有方法不是私有"bug" - > http://jira.codehaus.org/browse/GROOVY-1875
...但是,当然,这是一个可能在某个时刻解决的错误所以我不会依赖于此(我会吗?)
那么......在groovy中测试受限制方法的首选方法是什么?