Maven+spring+ibatis+struts2.0+MQ+Memcached 项目构建
来源:互联网 发布:java实现员工管理系统 编辑:程序博客网 时间:2024/06/06 01:34
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=cn.wonhigh.retail -DartifactId=retail-mobile-admin -Dversion=0.1.0
cd TestSSI-2.0 进入主目录然后分别建立目录
修改里面的jar为pom
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-api -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-dal -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-manager -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-service -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-web -Dversion=0.1.0 -DarchetypeArtifactId=maven-archetype-webapp
3:mvn eclipse:eclipse
要以导入ecliesp
4:依赖关系 :
<dependency>
<groupId>com.xiu.channel.core</groupId>
<artifactId>channel-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
一般来讲,web 依赖 core model util
core 依赖于model util ,pereist
5:一般来讲web 下的resoures文件用来放配置文件
SSI常用的经常出问题的地方:
A:使用Hassion
1:spring里面配置:
<bean id="inventoryService"
class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>${tm.channel}/inventoryservice</value>
</property>
<property name="serviceInterface">
<value>com.xiu.channel.inventory.api.InventoryService</value>
</property>
</bean>
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<BizOrderDO> bizOrderDOList = new ArrayList<BizOrderDO>();
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[i];
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:
配置文件:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 配置JMS连接工厂 -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.80.82:61616"/>
</bean>
<!-- 配置JMS模版 -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<!-- 发送消息的目的地(一个队列) -->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
<!-- 设置消息队列的名字 -->
<constructor-arg index="0" value="HelloWorldQueue"/>
</bean>
</beans>
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[color=red][/color]
MM中数据的存储和更新操作是以如下文本格式的协议规定的命令。
<command name> <key> <flags> <exptime> <bytes> \r\n
<data-block>
向MM中存取数据的常用命令和参数说明如下。
<command name>为set,表示向MM中存入一条记录。
key表示这条记录的键值。
flags是一个十进制的int,表示存储记录时的客户端标志,在记录取出时会返回。
exptim表示数据的过期时间,0表示永不过期,其他数值则表示有效的毫秒数,在过
期时间之后,客户端将取不到这条记录,MM中的过期记录会被清空或删除。
bytes表示这条命令要保存的数据字节的长度,回车后即可输入要保存的数据。
<data-block>即要保存的数据,其长度必须和bytes值对应
Replace命令:用以替换MM中某key对应的值。
Delete命令:用以从MM中删除一条记录,
想知道当前MM服务器的状态相关数据,请输入stats命令
显示当前MM服务器中的读取字节数、缓存命中率、空间大小等
打包到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=cn.wonhigh.retail -DartifactId=retail-mobile-admin -Dversion=0.1.0
cd TestSSI-2.0 进入主目录然后分别建立目录
修改里面的jar为pom
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-api -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-dal -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-manager -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-service -Dversion=0.1.0
mvn archetype:create -DgroupId=cn.wonhigh.retail -DartifactId=retail-mobile-admin-common-web -Dversion=0.1.0 -DarchetypeArtifactId=maven-archetype-webapp
3:mvn eclipse:eclipse
要以导入ecliesp
4:依赖关系 :
<dependency>
<groupId>com.xiu.channel.core</groupId>
<artifactId>channel-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
一般来讲,web 依赖 core model util
core 依赖于model util ,pereist
5:一般来讲web 下的resoures文件用来放配置文件
SSI常用的经常出问题的地方:
A:使用Hassion
1:spring里面配置:
<bean id="inventoryService"
class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>${tm.channel}/inventoryservice</value>
</property>
<property name="serviceInterface">
<value>com.xiu.channel.inventory.api.InventoryService</value>
</property>
</bean>
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<BizOrderDO> bizOrderDOList = new ArrayList<BizOrderDO>();
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[i];
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:
配置文件:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- 配置JMS连接工厂 -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.80.82:61616"/>
</bean>
<!-- 配置JMS模版 -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<!-- 发送消息的目的地(一个队列) -->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
<!-- 设置消息队列的名字 -->
<constructor-arg index="0" value="HelloWorldQueue"/>
</bean>
</beans>
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[color=red][/color]
MM中数据的存储和更新操作是以如下文本格式的协议规定的命令。
<command name> <key> <flags> <exptime> <bytes> \r\n
<data-block>
向MM中存取数据的常用命令和参数说明如下。
<command name>为set,表示向MM中存入一条记录。
key表示这条记录的键值。
flags是一个十进制的int,表示存储记录时的客户端标志,在记录取出时会返回。
exptim表示数据的过期时间,0表示永不过期,其他数值则表示有效的毫秒数,在过
期时间之后,客户端将取不到这条记录,MM中的过期记录会被清空或删除。
bytes表示这条命令要保存的数据字节的长度,回车后即可输入要保存的数据。
<data-block>即要保存的数据,其长度必须和bytes值对应
Replace命令:用以替换MM中某key对应的值。
Delete命令:用以从MM中删除一条记录,
想知道当前MM服务器的状态相关数据,请输入stats命令
显示当前MM服务器中的读取字节数、缓存命中率、空间大小等
- Maven+spring+ibatis+struts2.0+MQ+Memcached 项目构建
- Maven+spring+ibatis+struts2.0+MQ+Memcached 项目构建
- MAVEN构建spring struts2 ibatis框架整合开发 使用包
- maven构建struts2+spring项目简单实例
- Maven构建Struts2+Hibernate+Spring web项目
- Maven - 构建Struts2项目
- 使用 maven 构建 全注解spring+ hibernate4 + struts2 项目
- maven构建Spring项目
- 使用Maven构建Struts2项目
- 使用Maven构建Struts2项目
- maven项目构建spring项目
- 构建开源的项目环境(Spring/ibatis/maven/nexus)
- 使用Maven构建Spring项目
- Maven构建spring+redis项目
- maven搭建spring mvc+ibatis项目
- maven搭建spring mvc+ibatis项目 .
- maven搭建spring mvc+ibatis项目
- maven搭建spring mvc+ibatis项目
- 大O表示法
- 如何在razer中调用方法
- ActiveMQ+Spring2.5(转)
- java 一个用户在同一时间只能登录一次的绝佳解决方案
- Dom 解析
- Maven+spring+ibatis+struts2.0+MQ+Memcached 项目构建
- JQUERY 常用方法总结
- HDU1879--继续畅通工程
- java中join(),yield(),sleep()以及wait()的区别(转)
- 第九周项目1:Complex类
- oracle 存储过程
- 线程堵塞
- Spring 线程池使用
- 特殊的队列:BlockingQueue 使用(转)