小编Art*_*lan的帖子

Spring 4 websocket + Tomcat 7.54异步支持不起作用

我正在使用Spring websockets和stomp.js创建一个示例聊天应用程序,我正在使用tomcat 7.54,但在运行应用程序时,我在浏览器发出xhr请求时遇到了异步支持的错误.

服务器信息:Apache Tomcat/7.0.54 Servlet版本:3.0 JSP版本:2.2 Java版本:1.7.0_25

在web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
    <async-supported>true</async-supported>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
Run Code Online (Sandbox Code Playgroud)

调度员servlet.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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:websocket="http://www.springframework.org/schema/websocket"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.htm">indexController</prop>
            </props>
        </property>
    </bean>

    <context:component-scan base-package="hello" />

    <websocket:message-broker application-destination-prefix="/app">
        <websocket:stomp-endpoint path="/hello">
            <websocket:sockjs/>
        </websocket:stomp-endpoint>
        <websocket:simple-broker prefix="/topic"/>
    </websocket:message-broker> …
Run Code Online (Sandbox Code Playgroud)

spring tomcat servlets spring-mvc spring-websocket

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

GatewayProxyFactoryBean抛出的运行时异常

迁移到Spring Integration 4.0.4时,使用使用以下创建的服务bean时会引发以下异常GatewayProxyFactoryBean:

Sep 30, 2014 3:45:21 PM org.springframework.integration.expression.ExpressionUtils createStandardEvaluationContext
WARNING: Creating EvaluationContext with no beanFactory
java.lang.RuntimeException: No beanfactory
    at org.springframework.integration.expression.ExpressionUtils.createStandardEvaluationContext(ExpressionUtils.java:79)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.createMethodInvocationEvaluationContext(GatewayMethodInboundMessageMapper.java:182)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.access$000(GatewayMethodInboundMessageMapper.java:77)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper$DefaultMethodArgsMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:279)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper$DefaultMethodArgsMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:272)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.mapArgumentsToMessage(GatewayMethodInboundMessageMapper.java:158)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:153)
    at org.springframework.integration.gateway.GatewayMethodInboundMessageMapper.toMessage(GatewayMethodInboundMessageMapper.java:77)
    at org.springframework.integration.support.converter.SimpleMessageConverter.toMessage(SimpleMessageConverter.java:82)
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:112)
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:103)
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:241)
    at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:220)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:341)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:304)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:295)
Run Code Online (Sandbox Code Playgroud)

我们的设计GatewayProxyFactoryBean广泛使用,这个例外似乎是新的.在这种情况下,我们不使用任何SpEL表达式.如何避免这种异常?

spring-integration

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

KafkaException:无法实例化类JsonDeserializer

我正在尝试使用Kafka客户端按照此参考指南启动Spring Boot应用程序,我收到以下错误.
你能告诉我如何修理吗?

@Bean
public Map<String, Object> consumerConfig() {
    final HashMap<String, Object> result = new HashMap<>();
    result.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, env.getProperty("spring.kafka.bootstrap.servers"));
    result.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class);
    result.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
    return result;
}

@Bean
public ConsumerFactory<Long, String> consumerFactory() {
    return new DefaultKafkaConsumerFactory<>(consumerConfig());
}

@Bean
ConcurrentKafkaListenerContainerFactory<Long, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<Long, String> containerFactory = new ConcurrentKafkaListenerContainerFactory<>();
    containerFactory.setConsumerFactory(consumerFactory());
    containerFactory.setConcurrency(3);
    containerFactory.getContainerProperties().setPollTimeout(3000);
    return containerFactory;
}
Run Code Online (Sandbox Code Playgroud)

-

org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-kafka

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

Spring集成注释Java 8可选的错误处理

我正在使用Spring启动1.2.2.Release和Java 8,问题是Spring Optional payload在传递它时多次包装到新的Optional对象中transformer/service activator.例如

@ServiceActivator(inputChannel = ..., outputChannel = ...) 
public Optional<Foo> transform() {returns -> Optional.of(foo);}

@ServiceActivator(inputChannel = ..., outputChannel = ...)
public Optional<Foo> doSomething1(Optional<Foo> payload) {
     payload.ifPresent(f -> {System.out.println(f.getId());}); // this line throws ClassCastException 
  return foo;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码抛出ClassCastExcpetion(无法将java.util.Optional强制转换为Foo)的原因是因为payload而不是包含foo值包含另一个可选对象,而Optional对象包含foo为value.

我已经在这里提到了这个

现在,Spring Integration始终处理Java 8的Optional类型.

我甚至尝试过使用文档中提到的框架的确切版本但没有成功

解决方法:我尝试创建一些包含有效负载的Wrapper(PayloadWrapper)对象,它可以工作.但可能还有其他一些方法吗?

java spring spring-integration java-8 spring-boot

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

Spring集成异常

我在spring集成中遇到异常.以下是我的spring.xml文件的片段

<int-file:inbound-channel-adapter id=ïncomingFile" directory="file:${myapp.incomingFile.path}"prevent-duplicates="true"filename-regex="${filenameRegex}>

<int:poller id="poller"fixed-delay="5000"/>

</int-file:inbound-channeladapter> 
Run Code Online (Sandbox Code Playgroud)

例外:

7 May 2014 13:52:17.903 [main] INFO  App.main - Starting with the main application
May 17, 2014 1:52:18 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2814a18d: startup date [Sat May 17 13:52:18 EDT 2014]; root of context hierarchy
May 17, 2014 1:52:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:./src/main/resources/spring//Spring-All-Module.xml]
May 17, 2014 1:52:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:src/main/resources/spring//filetracker.xml]
May 17, 2014 1:52:18 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties …
Run Code Online (Sandbox Code Playgroud)

spring spring-integration

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

Spring框架监视ThreadPoolTask​​Executor队列大小

我检查http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTask​​Executor.html

队列大小没有getter,只有队列容量.

如果我使用jmx来监视ThreadPoolTask​​Executor,我如何监视队列大小级别以确保它是健康的?

spring jmx spring-jmx jmxtrans

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

无法提取响应:找不到合适的HttpMessageConverter用于响应

好吧,我试图在Spring中使用RestTemplate来使用REST Web服务.该服务返回一个JSON,其中包含对象列表,如下所示.

[
  {
    "name": "123",
    "ids": {
      "y": 36.41666667,
      "x": 39.58333333,
      "z": 12
    },
    "ip": "10.219.90.12",
    "rate": 67.5,
    "id": 1
  },
  {
    "name": "123",
    "ids": {
      "y": 72.5,
      "x": 15.16666667,
      "z": 12
    },
    "ip": "10.219.90.13",
    "rate": 67.5,
    "aarid": 2
  },
  {
    "name": "123",
    "ids": {
      "y": 0,
      "x": 14.33333333,
      "z": 12
    },
    "ip": "10.219.90.14",
    "rate": 67.5,
    "id": 3
  }]
Run Code Online (Sandbox Code Playgroud)

我为此JSON定义了一个POJO.

public class Data {

    @JsonProperty("name")
    private String name;
    @JsonProperty("ip")
    private String ip;
    @JsonProperty("rate")
    private Double rate;
    @JsonProperty("id")
    private Long …
Run Code Online (Sandbox Code Playgroud)

spring-integration spring-rest

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

春季:配置

在Spring Java配置中,假设我想@Bean在另一个@Bean定义中重复使用a 。我可以在一个文件中执行此操作:

@Bean
public A buildA() {
    return new A();
}

@Bean
public B buildB() {
    return new B(buildA());
}
Run Code Online (Sandbox Code Playgroud)

或者我可以在一个文件中配置A,然后在另一个文件中将其自动连接,例如(为简洁起见,请使用字段注入):

@Autowired
private A a;

@Bean
public B buildB() {
    return new B(a);
}
Run Code Online (Sandbox Code Playgroud)

我想知道这两种可能性是否完全相同?对我来说,第一个版本可能会使A两次虚假,而第二个版本则不会。

我问这个问题,因为在我的特殊用例中,A正在建立与消息传递代理的连接,并且我有几个B在消耗流(我是.toReactivePublisher()从A中的Spring集成中使用的),并且我不想连接两次或更多给经纪人。

spring spring-java-config

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

如何在Spring Integration中从表达式中调用类的方法

如何从spring集成EXPRESSION中调用方法:

<int:chain input-channel="service.activator.out">
           <int:header-enricher>
              <int:header name="LIST_DATA"
             expression="**HERE NEEDS TO CALL A METHOD OF CLASS BY PASSING PAYLOAD**"/>     
         </int:header-enricher>
</int:chain>
Run Code Online (Sandbox Code Playgroud)

spring-integration

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

从脚本启动 Spring Boot 应用程序

使用普通的 spring mvn 命令,我可以从命令行启动一个 spring 启动应用程序,并用 Control+c 终止它。然而,我已经创建了一堆服务,稍后我将对其进行 dockerize。现在它们是由 mvn 生成的普通 java jar 文件。我如何使用python脚本或Bash脚本将它们一一启动,然后使用脚本终止它们。有什么方法可以让我启动它并且脚本不会阻止并且应用程序会有一个我以后可以用来停止应用程序的名称?

java spring spring-boot

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

Spring Framework 中@PropertySource 和@DynamicPropertySource 的区别

属性 @DynamicPropertySource 作为 Spring Framework 5.2.5 版的一部分添加。在官方文件说:

该注解及其支持基础设施最初旨在允许基于 Testcontainers 的测试的属性轻松暴露给 Spring 集成测试。但是,此功能也可以与任何形式的外部资源一起使用,其生命周期在测试的 ApplicationContext 之外维护。

还有一个基本的例子:

@SpringJUnitConfig(...)
@Testcontainers 
class ExampleIntegrationTests { 
@Container 
static RedisContainer redis = new RedisContainer(); // ...
@DynamicPropertySource 
static void redisProperties(DynamicPropertyRegistry registry) { 
registry.add("redis.host", redis::getContainerIpAddress);
 registry.add("redis.port", redis::getMappedPort);
 } }
Run Code Online (Sandbox Code Playgroud)

但是,我不明白……当我们有行为相同的@PropertySource时,这个新注释的用例是什么?

spring spring-boot

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