gpt4 book ai didi

java - 为什么我的 main 方法一直在运行?

转载 作者:行者123 更新时间:2023-12-01 14:22:39 25 4
gpt4 key购买 nike

我正在做一个 spring-integration +rabbitMQ 应用程序。从主类中,我调用一个网关,将我的消息发送到rabbitmq,它工作得很好,但由于某种奇怪的原因,我的主要方法继续运行,起初我认为我可能在我的 spring 上下文中留下了一个轮询器,但是那'事实并非如此。这是我的代码:

public final class Main {

private static final Logger LOGGER = Logger.getLogger(Main.class);

@Autowired
static
ChatGateway chatGateway;

private Main() { }

/**
* Load the Spring Integration Application Context
*
* @param args - command line arguments
*/
public static void main(String args[]) {
Mensaje mensaje = new Mensaje();
mensaje.setClienteID("clienteXXX");

ClassPathXmlApplicationContext ctx = new
ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/spring-integration-context.xml");
chatGateway = (ChatGateway) ctx.getBean("chatGateway");

chatGateway.enviarAlarma(mensaje);

}
}

这是我的 spring 上下文:

<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<!-- From STDIN To RabbitMQ

<int-stream:stdin-channel-adapter id="consoleIn"
channel="toRabbit">
<int:poller fixed-delay="1000" max-messages-per-poll="1" />
</int-stream:stdin-channel-adapter>
-->

<int:channel id="toRabbit" />

<int:gateway id="chatGateway"
service-interface="com.praxis.chat.gateway.ChatGateway"
default-request-channel="toRabbit" />

<int-amqp:outbound-channel-adapter
channel="toRabbit" amqp-template="amqpTemplate" exchange-name="si.test.exchange"
routing-key="si.test.binding" />


<!-- Infrastructure -->

<rabbit:connection-factory id="connectionFactory" />

<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" />

<rabbit:admin connection-factory="connectionFactory" />

<rabbit:queue name="si.test.queue" />

<rabbit:direct-exchange name="si.test.exchange">
<rabbit:bindings>
<rabbit:binding queue="si.test.queue" key="si.test.binding" />
</rabbit:bindings>
</rabbit:direct-exchange>

</beans>

为什么我的 main 方法在发送消息后仍然继续运行?提前致谢。

最佳答案

它会继续下去,因为它还没有被告知结束。

您可以使用:

System.exit(0);

返回;

main(String[] args)的末尾

关于java - 为什么我的 main 方法一直在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17410693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com