spring+jms+weblogic

<?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:context="http://www.springframework.org/schema/context" xmlns:jms="http://www.springframework.org/schema/jms" xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">

	<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>jmsConnectionFactory</value>
		</property>
		<property name="jndiTemplate">
			<ref bean="jmsJndiTemplate"></ref>
		</property>
	</bean>
	<bean id="jmsDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>ResponseQueueName</value>
		</property>
		<property name="jndiTemplate">
			<ref bean="jmsJndiTemplate"></ref>
		</property>
	</bean>
	<bean id="jmsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
		<property name="environment">
			<props>
				<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
				<prop key="java.naming.provider.url">t3://127.0.0.1:7001</prop>
			</props>
		</property>
	</bean>
	<!-- JMS Queue Send Template  -->
	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory">
			<ref local="jmsConnectionFactory" />
		</property>
		<property name="defaultDestination">
			<ref local="jmsDestination" />
		</property>
	</bean>

	<bean id="jmsProducer" class="org.springframework.samples.jpetstore.jms.JmsProducer">
		<constructor-arg ref="jmsTemplate" />
	</bean>

	<bean id="messageListener" class="org.springframework.samples.jpetstore.jms.JpetstoreJmsListener" />

	<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
		<!--property name="concurrentConsumers" value="5" /-->
		<property name="connectionFactory" ref="jmsConnectionFactory" />
		<property name="destination" ref="jmsDestination" />
		<property name="messageListener" ref="messageListener" />
		<property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" />
	</bean>
</beans>

 

package org.springframework.samples.jpetstore.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class JpetstoreJmsListener implements MessageListener {
	public void onMessage(Message message) {
		if (message instanceof TextMessage) {
			try {
				System.out.println("ok--" + ((TextMessage) message).getText());
			} catch (JMSException e) {
				throw new RuntimeException(e);
			}
		} else {
			throw new IllegalArgumentException("Message must be of type TestMessage");
		}
	}
}

 

package org.springframework.samples.jpetstore.jms;

import org.springframework.jms.core.JmsTemplate;

public class JmsProducer {

	private JmsTemplate jmsTemplate;

    public JmsProducer(JmsTemplate jmsTemplate) {
            this.jmsTemplate = jmsTemplate;
    }

    public void sendMessage() {
            jmsTemplate.convertAndSend("Hello world!("+System.currentTimeMillis()+")");
    }
}

 

import java.io.IOException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.samples.jpetstore.jms.JmsProducer;

public class TestJms {
	public static void main(String[] args) throws IOException {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		JmsProducer sender = (JmsProducer) context.getBean("jmsProducer");
		sender.sendMessage();
	}
}

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>jms</groupId>
	<artifactId>jms</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>jms</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jms</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>javax.annotation</groupId>
			<artifactId>jsr250-api</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-core</artifactId>
			<version>5.7.0</version>
		</dependency>
		<!--weblogic JMS依赖下面两个包 -->
		<dependency>
			<groupId>weblogic</groupId>
			<artifactId>wlclient</artifactId>
			<version>9.2.3</version>
		</dependency>
		<dependency>
			<groupId>weblogic</groupId>
			<artifactId>wljmsclient</artifactId>
			<version>9.2.3</version>
		</dependency>
	</dependencies>


</project>

 

你可能感兴趣的:(weblogic)