小编sel*_*rce的帖子

Spring Integration:如何一次处理多条消息?

我有以下配置:

<bean id="mongoDbMessageStore" class="org.springframework.integration.mongodb.store.MongoDbMessageStore">
    <constructor-arg ref="mongoDbFactoryDefault"/>
</bean>

<!-- the queue capacity is unbounded as it uses a persistent store-->
<int:channel id="logEntryChannel">
    <int:queue message-store="mongoDbMessageStore"/>
</int:channel>

<!-- the poller will process 10 messages every 6 seconds -->
<int:outbound-channel-adapter channel="logEntryChannel" ref="logEntryPostProcessorReceiver" method="handleMessage">
    <int:poller max-messages-per-poll="10" fixed-rate="6000"/>
</int:outbound-channel-adapter>
Run Code Online (Sandbox Code Playgroud)

并将消息处理程序定义为

@Override
public void handleMessage(Message<?> message) throws MessagingException {
    Object payload = message.getPayload();
    if (payload instanceof LogEntry) {
        LogEntry logEntry = (LogEntry) payload;
        String app = (String) message.getHeaders().get("app");
        logger.info("LogEntry Received - " + app + " " …
Run Code Online (Sandbox Code Playgroud)

xml spring message-queue spring-integration

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

Spring HandlerInterceptor:如何访问类注释?

我使用以下代码注册了我的拦截器

@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
 ...
 @Override
 public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor( myInterceptor() );
 }
 ...
}
Run Code Online (Sandbox Code Playgroud)

这里是拦截器定义

public class MyInterceptorimplements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

    // Check to see if the handling controller is annotated
    for (Annotation annotation : Arrays.asList(handler.getClass().getDeclaredAnnotations())){
        if (annotation instanceof MyAnnotation){
            ... do something
Run Code Online (Sandbox Code Playgroud)

但是,handler.getClass().getDeclaredAnnotations()不会返回截获的Controller的类级别注释.

我只能得到方法级注释,这不是我想要的.

相同的拦截器适用于xml配置(使用Spring 3):

<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="interceptors">
        <list>
            <ref bean="myInterceptor"/>
        </list>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

有没有办法在Spring 4中提供类级信息?

根据 In-Spring-mvc拦截器,我如何访问处理程序控制器方法? …

java spring spring-mvc

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