出于何种目的,在此代码中使用循环
public final int getAndSet(int newValue) {
for (;;) {
int current = get();
if (compareAndSet(current, newValue))
return current;
}
}
Run Code Online (Sandbox Code Playgroud) 这就是我创建交换并将队列绑定到它的方式
<rabbit:topic-exchange id="dataExchange" name="MQ-EXCHANGE" durable="true">
<rabbit:bindings>
<rabbit:binding queue="COMM_QUEUE" pattern="queue.*" />
</rabbit:bindings>
</rabbit:topic-exchange>
Run Code Online (Sandbox Code Playgroud)
我已经在互联网上阅读了很多帖子,其中写道如果要保护兔子或队列崩溃,还需要将消息标记为持久性.但我无法弄清楚如何标记我的消息持久性.
这就是我将消息发布到队列的方式
@Autowired
private RabbitTemplate template;
@Override
public void produceMessage(Object message, String routingKey) {
template.convertAndSend(routingKey, message);
}
Run Code Online (Sandbox Code Playgroud)
我找了不同的API方法来了解这一点,并试图寻找我可以在XML中配置但无法找到方法的任何特定属性.任何指导?
我正在尝试从Spring 3.x迁移到Spring 4.x,但无法正确加载Spring Security XML文件.
我认为需要更改XML配置,但我在INTERNET上找不到相同的配置.与Spring 3.x一起使用的XML配置不适用于4.0.1.RELEASE.
这是我的XML配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<!-- This is where we configure Spring-Security -->
<security:http auto-config="false" use-expressions="true"
entry-point-ref="authenticationEntryPoint" disable-url-rewriting="true" >
<!-- Below URL's will be intercepted by spring security -->
<security:intercept-url pattern="/access/login" access="permitAll"/>
<security:intercept-url pattern="/analytics/**" access="hasAnyRole('ROLE_ADMIN', 'ROLE_USER')"/>
<security:intercept-url pattern="/access/auth/**" access="hasRole('ROLE_ADMIN')"/>
<security:intercept-url pattern="/access/**" access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')"/>
<security:intercept-url pattern="/auth/**" access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')"/>
<!-- Logout Configuration -->
<security:logout invalidate-session="true" logout-success-url="/access/login" logout-url="/access/logout" />
<!-- Authentication --> …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,我需要为其构建响应,以防请求中发送无效的 JSON 负载。
目前,服务器端收到的异常消息是意外字符('"'(代码 34)):需要逗号分隔 [来源:org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@310db662; 行中的 OBJECT 条目:13,栏:7]
这就是我试图实现它的方式......
import java.util.ArrayList;
import java.util.List;
import javax.validation.ConstraintDeclarationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Provider
public class JsonParseExceptionMapper implements ExceptionMapper<JsonProcessingException> {
private static Logger logger = LogManager.getLogger(JsonParseExceptionMapper.class.getName());
@Override
public Response toResponse(final JsonProcessingException ex) {
System.out.println("inside json parse exception mappper");
logger.error(messages.toString());
return Response.status(Response.Status.BAD_REQUEST).entity(messages).type(MediaType.APPLICATION_JSON).build();
}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个类似的 ExceptionMapper ,它捕获 ConstraintViolationException ,它工作得很好。
我还按照互联网上的建议尝试了一些不同的例外情况,仅举几例
JsonProcessingException
BadRequestException
JsonParseException
InvalidFormatException
ConstraintDeclarationException
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,上述例外似乎都不起作用。有谁知道应该将哪种异常与 ExceptionMapper 结合使用来捕获此类情况。
另外,我猜想可能有多个 ExceptionMapper 实现彼此并行运行。如果我错了,请纠正。
编辑:这就是我所说的无效 JSON 有效负载的意思,请注意校验和之前缺少的逗号
{ …Run Code Online (Sandbox Code Playgroud) java ×2
concurrency ×1
jersey ×1
json ×1
rabbitmq ×1
rest ×1
spring ×1
spring-amqp ×1
validation ×1