struts.convention.result.path="/WEB-INF/content/": 结果页面存放的根路径,必须以 "/" 开头。 struts.convention.action.suffix="Action": action名字的获取 struts.convention.action.name.lowercase="true": 是否将Action类转换成小写 struts.convention.action.name.separator="-": struts.convention.action.disableScanning="false": 是否不扫描类。 struts.convention.default.parent.package="convention-default":设置默认的父包。 struts.convention.package.locators="action,actions,struts,struts2": 确定搜索包的路径。 struts.convention.package.locators.disable="false": struts.convention.package.locators.basePackage="":
struts2零配置详细可看这篇http://javeye.iteye.com/blog/358744
spring配置文件从外部加载properties文件
<!-- 定义易受环境影响的变量 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <!-- 标准配置 --> <value>classpath*:/application.properties</value> <!-- 本地开发环境配置 --> <value>classpath*:/application.local.properties</value> <!-- 服务器生产环境配置 --> <value>file:/var/mini-service/application.server.properties</value> </list> </property> </bean>
基于cxf集成spring开发webservice客户端技术 很简单:
<?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:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" default-lazy-init="true"> <description>Apache CXF Web Service Client端配置</description> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <jaxws:client id="userWebService" serviceClass="org.springside.examples. miniservice.ws.UserWebService" address="http://localhost:8080/mini-service/ws/userservice" /> </beans> <!--这个是webservice客现类接口-->
利用cxf本身API开发webservice 也很简单:
String address = BASE_URL + "/ws/userservice"; JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setAddress(address); proxyFactory.setServiceClass(UserWebService.class); //UserWebService是一个接口 UserWebService userWebServiceCreated = (UserWebService) proxyFactory.create(); //(可选)重新设定endpoint address. ((BindingProvider) userWebServiceCreated).getRequestContext() .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
利用velocity解释动态sql。不再需要为拼sql头痛了。
/** * 使用Velocity生成内容的工具类. * * @author calvin */ public class VelocityUtils { static { try { Velocity.init(); } catch (Exception e) { throw new RuntimeException("Exception occurs while initialize the velociy.", e); } } /** * 渲染内容. * * @param template 模板内容. * @param model 变量Map. */ public static String render(String template, Map<String, ?> model) { try { VelocityContext velocityContext = new VelocityContext(model); StringWriter result = new StringWriter(); Velocity.evaluate(velocityContext, result, "", template); return result.toString(); } catch (Exception e) { throw new RuntimeException("Parse template failed.", e); } } }
调用:
/** * 使用Velocity创建动态SQL. */ public List<User> searchUserByFreemarkerSqlTemplate(Map<String, ?> conditions) { String sql = VelocityUtils.render(searchUserSql, conditions);//searchUserSql由spring注入 logger.info(sql); return jdbcTemplate.query(sql, userMapper, conditions); }
<bean id="userJdbcDao" class="org.springside.examples.showcase.common.dao.UserJdbcDao"> <property name="searchUserSql"> <value><![CDATA[ SELECT id, name, login_name FROM ss_user WHERE 1=1 ## Dynamic Content #if ($loginName) AND login_name=:loginName #end #if ($name) AND name=:name #end ORDER BY id ]]></value> </property> </bean>
jdbcTeamplate 使用Bean形式命名参数
private static final String INSERT_USER = "insert into SS_USER(id, login_name, name) values(:id, :loginName, :name)";
//使用BeanPropertySqlParameterSource将User的属性映射为命名参数. BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(user); jdbcTemplate.update(INSERT_USER, source);
webservice.利用mtom协义传传大文件
/** * 演示以MTOM附件协议传输Streaming DataHandler的二进制数据传输的方式. * * @author calvin */ @XmlType(name = "LargeImageResult", namespace = WsConstants.NS) public class LargeImageResult extends WSResult { private static final long serialVersionUID = 8375875101365439245L; private DataHandler imageData; @XmlMimeType("application/octet-stream") public DataHandler getImageData() { return imageData; } public void setImageData(DataHandler imageData) { this.imageData = imageData; } }
@WebService(serviceName = "LargeImageService", portName = "LargeImageServicePort", endpointInterface = "org.springside.examples.showcase.ws.server.LargeImageWebService", targetNamespace = WsConstants.NS) public class LargeImageWebServiceImpl implements LargeImageWebService, ApplicationContextAware { private static Logger logger = LoggerFactory.getLogger(LargeImageWebServiceImpl.class); private ApplicationContext applicationContext; /** * @see LargeImageWebService#getImage() */ public LargeImageResult getImage() { try { //采用applicationContext获取Web应用中的文件. File image = applicationContext.getResource("/img/logo.jpg").getFile(); //采用activation的DataHandler实现Streaming传输. DataSource dataSource = new FileDataSource(image); DataHandler dataHandler = new DataHandler(dataSource); LargeImageResult result = new LargeImageResult(); result.setImageData(dataHandler); return result; } catch (IOException e) { logger.error(e.getMessage(), e); return WSResult.buildResult(LargeImageResult.class, WSResult.IMAGE_ERROR, "Image reading error."); } } public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } }
springside很强大,这些主流的大派对,这是不就是我们平常所要找的答案吗?很多技术因为没用,快忘记了,暂时作一个小笔记先。未完待续。。