java - 在 Java 中运行两次 GUI 应用程序

标签 java spring swing

我在 java 中有一个小的 gui swing 应用程序(聊天),我需要多次运行它,每次它都应该给我一个 GUI 聊天窗口,

它第一次运行良好,当我尝试在 IntelliJ 中再次运行相同的应用程序时,它不会再生成 GUI 窗口

非常感谢任何帮助提前谢谢

public static void main(String[] args) throws IOException, InterruptedException, SQLException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("sconfig.xml");
    CClient client = (CClient) context.getBean("simpleClient");
    client.init();
}

应用上下文:

 <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL">
        <!-- value>tcp://localhost:61616</value -->
        <value>vm://localhost</value>
    </property>
</bean>

<!-- <bean id="pooledJmsConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
      destroy-method="stop">
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>-->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="jmsExample" />
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="simpleClient" class="com.CClient">
    <property name="template" ref="jmsTemplate"/>
    <property name="destination" ref="destination" />
</bean>

<bean id="messageListener" class="com.ExampleListener" />

<!-- and this is the message listener container -->
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
    <property name="destination" ref="destination"/>
    <property name="messageListener" ref="messageListener" />
</bean>

最佳答案

没有理由启动一个应用程序一次就可以正常工作,而第二次启动它就没有任何作用,因为它们是在不同的 JVM 中启动的。如果第一次启动尝试打开 TCP 套接字或锁定文件,而第二次启动尝试做同样的事情,则可能会出现问题。

但我认为解释是您在运行配置中选中了“仅单个实例”复选框,这正是用于使 IntelliJ 一次仅启动您的应用程序实例的一个实例。

如果不是这种情况,请提供更多详细信息:启动第二个应用程序时会发生什么?你有异常(exception)吗?如果是这样,堆栈跟踪是什么?如果不是,您的应用程序是做什么的?

关于java - 在 Java 中运行两次 GUI 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14568367/

相关文章:

java - 如何: JTable with collapsible JTree in first column and data in the other columns?

java - 如何通过 api url 索引使用 recyclerview 实现分页

java - 如何在 spring application.properties 中指定我的 ssl keystore 文件的本地文件路径?

java - 将 JPanel 的区域转换为 BufferedImage

java - 在 Spring Boot 项目中找不到页面

spring - 无法使用单向 @OneToMany 关系 JPA 获取记录

java - 在 JLabel 上显示加密图像

java - Hibernate 在多对多列表上创建别名

java - OnClickListener = 向下 + 向上?安卓

java - 创建 QName 异常时,Opensaml unmarshallMessage 给出 opensaml 本地部分不能为 "null"