ITeye博客

Maven+spring+ibatis+struts2.0+MQ+Memcached 项目构建

rainyear · 2012-02-28 11:27 · 框架开发 · 非技术 · Markdown

1>Maven一些基本命令: 打包到eclipse中的命令:mvn eclipse:eclipse 打包到eclipse中的命令:mvn eclipse:clean eclipse:eclipse

2:建立环境变量:在path 目录下建立: D:\apache-maven-3.0.3\bin 到你新建的文件夹下。 例如:你新建了一个文件夹:F:\WorkSpace
CMD进入: mvn archetype:create -DgroupId=com.xiu.TestSSI -DartifactId=TestSSI-2.0 -Dversion=1.0 cd TestSSI-2.0 进入主目录然后分别建立目录 mvn archetype:create -DgroupId=com.xiu.TestSSI.api -DartifactId=TestSSI-api -Dversion=1.0 mvn archetype:create -DgroupId=com.xiu.TestSSI.web -DartifactId=TestSSI-web -Dversion=1.0 -DarchetypeArtifactId=maven-archetype-webapp mvn archetype:create -DgroupId=com.xiu.TestSSI.util -DartifactId=TestSSI-util -Dversion=1.0 mvn archetype:create -DgroupId=com.xiu.TestSSI.model -DartifactId=TestSSI-model -Dversion=1.0 mvn archetype:create -DgroupId=com.xiu.TestSSI.persist -DartifactId=TestSSI-persist -Dversion=1.0 mvn archetype:create -DgroupId=com.xiu.TestSSI.core -DartifactId=TestSSI-core -Dversion=1.0

3:mvn eclipse:eclipse 要以导入ecliesp 4:依赖关系 : com.xiu.channel.core channel-core 1.0 org.springframework spring 2.5.6

一般来讲,web 依赖 core model util core 依赖于model util ,pereist

**5:一般来讲web 下的resoures文件用来放配置文件 **

SSI常用的经常出问题的地方:

A:使用Hassion

1:spring里面配置: ${tm.channel}/inventoryservice com.xiu.channel.inventory.api.InventoryService 2: OrderEntryService orderEntryService = null; try { String url = "http://localhost:8080/trade/remote/OrderEntryService"; HessianProxyFactory factory = new HessianProxyFactory(); orderEntryService = (OrderEntryService) factory.create(OrderEntryService.class, url); List bizOrderDOList = new ArrayList(); BizOrderDO order = new BizOrderDO(); orderEntryService.方法(order转值进来);

3;上面的要启动TOMCAT 不用启用TOMCAT情况: package com.xiu.tradecenter.core;

import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier;

import org.apache.commons.beanutils.PropertyUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.springframework.context.support.FileSystemXmlApplicationContext;

public abstract class BaseTest {

private static String configs = new String {
		"/../trade-biz-web/src/main/webconfig/spring-tc-dao.xml",
		"/../trade-biz-web/target/trade/WEB-INF/spring-tc-jdbc.xml",
// "/../tc-server/target/tradecenter/WEB-INF/spring-tc-service.xml"
};

protected static FileSystemXmlApplicationContext appContext;

@BeforeClass
public static void setUp() throws Exception {
	try {
		long start = System.currentTimeMillis();
		System.out.println("正在加载配置文件...");
		appContext = new FileSystemXmlApplicationContext(configs);
		System.out.println("配置文件加载完毕,耗时:"
				+ (System.currentTimeMillis() - start));
	} catch (Exception e) {
		e.printStackTrace();
	}
}

protected boolean setProtected() {
	return false;
}

@Before
public void autoSetBean() {
	// 自动注入Spring管理的Bean,不用每个测试类都去获取。
	PropertyDescriptor propertyDescriptors = PropertyUtils
			.getPropertyDescriptors(this.getClass());

	for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
		String propertyName = propertyDescriptor.getName();
		Class<?> propertyType = propertyDescriptor.getPropertyType();
		Method propertySetter = propertyDescriptor.getWriteMethod();

		if (propertySetter == null) {
			continue;
		}
		Object value;
		try {
			value = appContext.getBean(propertyName);

			if (value == null) {
				continue;
			}

			if (!propertyType.isInstance(value)) {
				continue;
			}
		} catch (Exception e) {
			continue;
		}
		try {
			propertySetter.invoke(this, new Object { value });
		} catch (Exception e) {
		}
	}
	if (setProtected()) {

		Class<?> clazz = getClass();

		do {
			Field fields = clazz.getDeclaredFields();

			for (int i = 0; i < fields.length; i++) {
				Field field = fields*;
				field.setAccessible(true);
				if (!Modifier.isStatic(field.getModifiers())
						&& Modifier.isProtected(field.getModifiers())) {
					Object oldValue = null;
					;
					try {
						oldValue = field.get(this);
					} catch (IllegalArgumentException e1) {
					} catch (IllegalAccessException e1) {
					}
					if (oldValue == null) {
						Object bean = appContext.getBean(field.getName());
						field.setAccessible(true);
						try {
							field.set(this, bean);
						} catch (IllegalArgumentException e) {
						} catch (IllegalAccessException e) {
						}
					} else {
					}
				}
			}
			clazz = clazz.getSuperclass();
		} while (!clazz.equals(BaseTest.class));
	}
}

@AfterClass
public static void tearDown() throws Exception {
	if (appContext != null) {
		appContext.destroy();
	}
}

}

然后调用

public class DrawApplyBOTest extends BaseTest {

private DrawApplyWriterService drawApplyWriterService;
public void setDrawApplyWriterService(
		DrawApplyWriterService drawApplyWriterService) {
	this.drawApplyWriterService = drawApplyWriterService;
}

@Test
public void insertDrawApplyTest() throws DAOException {
	DrawApplyDO drawApplyDO=new DrawApplyDO();
	//drawApplyDO.setAccountTotal(300);
	//drawApplyDO.setApplyAmount(200);
	 。。。。。。。

	Result result=drawApplyWriterService.insertDrawApply(drawApplyDO);
	System.out.println("i="+result.isSuccess());
}

** MQ: 配置文件:**













package com.xiu.TestGoodsCenter.core;

import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session;

import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; 发送消息 public class MySender {

/**
 * @param args
 */

// TODO Auto-generated method stub
public static void main(String args) {
	ApplicationContext ctx = new ClassPathXmlApplicationContext(
			"/applicationContext-test.xml");
	JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
	Destination destination = (Destination) ctx.getBean("destination");

	template.send(destination, new MessageCreator() {
		public Message createMessage(Session session) throws JMSException {
			return session
					.createTextMessage("发送消息:Hello ActiveMQ Text Message!");
		}
	});
	System.out.println("成功发送了一条JMS消息");
}

}

接收消息:

package com.xiu.TestGoodsCenter.core;

import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.TextMessage;

import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jms.core.JmsTemplate;

/**

  • 12.* 消息接收者 13.* 14.* @author jeff 15. */ public class MyReceiver { public static void main(String args) throws JMSException { ApplicationContext ctx = new ClassPathXmlApplicationContext( "/applicationContext-test.xml"); JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate"); Destination destination = (Destination) ctx.getBean("destination"); while (true) { TextMessage txtmsg = (TextMessage) template.receive(destination); if (null != txtmsg) System.out.println("收到消息内容为: " + txtmsg.getText()); else break; } } }

Memcached

1>在解压后的目录下,应存在一个memcached.exe文件,在命令执行安装命令,将其以系 统服务的形式安装,如图4.58所示。 cmd 进入目录然后执行命令:memcached.exe -d install 安装完毕后,在服务管理中即看到,MM已被安装为系统服务

2>安装完毕后,在服务管理中即看到,MM已被安装为系统服务,在系统服务里面启动服务

3>通过telnet连接MM启动后默认的端口11211 例:假如你的IP是:192.168.1.11 telnet 192.168.1.11 11211 连接服务器 通过telnet即可测试,例如,向MM中保存 key为netjava的值v2,保存时间是永不过期,然后再从MM中取出key为netjava的值,命令 执行格式如下: set javanet 0 0 2 wq STORED get javanet VALUE javanet 0 2 wq END

MM中数据的存储和更新操作是以如下文本格式的协议规定的命令。 \r\n 向MM中存取数据的常用命令和参数说明如下。  为set,表示向MM中存入一条记录。  key表示这条记录的键值。  flags是一个十进制的int,表示存储记录时的客户端标志,在记录取出时会返回。  exptim表示数据的过期时间,0表示永不过期,其他数值则表示有效的毫秒数,在过 期时间之后,客户端将取不到这条记录,MM中的过期记录会被清空或删除。  bytes表示这条命令要保存的数据字节的长度,回车后即可输入要保存的数据。 即要保存的数据,其长度必须和bytes值对应

Replace命令:用以替换MM中某key对应的值。 Delete命令:用以从MM中删除一条记录,

想知道当前MM服务器的状态相关数据,请输入stats命令 显示当前MM服务器中的读取字节数、缓存命中率、空间大小等

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。