Java

Where to put the environment-specific properties files when using spring framework ?

Where to put the environment-specific properties files when using spring framework ?  1. Put it on classpath?  Not acceptable.  Classpath means the file will be put in git/svn repository and there will only be one newest copy of it. As a result, all environments will have a same property file.  2. Put it on an …

Where to put the environment-specific properties files when using spring framework ? Read More »

Java code to show case how java client deals with https certificates

Visit a valid https site to see if there will be anything wrong public static void tryAuthorizedHttps() throws Exception { URL url = new URL(“https://www.baidu.com/”); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); InputStream in = conn.getInputStream(); String page = IOUtils.toString(in, “utf8”); System.out.println(page); // successfully printed System.out.println(“===================”); //get the first X509 cert on the certificate chain X509Certificate x5Cert …

Java code to show case how java client deals with https certificates Read More »

一个典型的centos + apache httpd + tomcat的配置

典型的java网站: 用centos做操作系统,用tomcat提供服务,用apache httpd做反向代理 apache httpd配置 引用 #一个IP多个域名 NameVirtualHost *:80 #禁止直接使用ip访问 <VirtualHost *:80>         ServerName 11.11.11.11         <Location />            Order deny,allow             Deny from all         </Location> </VirtualHost> #顶级域名跳转到www域名 <VirtualHost *:80>     ServerName my.com     RewriteEngine on     RewriteCond %{http_host} ^my.com [NC]     RewriteRule ^(.*)$ http://www.my.com/$1 [L,R=301] </VirtualHost> #把对apache的访问指向tomcat <VirtualHost *:80>     ServerName www.my.com     …

一个典型的centos + apache httpd + tomcat的配置 Read More »

eclipse代码生成模板:把一个bean的属性复制到另一个bean

生成代码,把一个bean的属性复制到另一个bean (两个bean未必同类型,但有一些共同的属性) ${:import(java.lang.reflect.Method)} public static void main(String args[]) { Class<?> destinClass = ${DestinBean}.class; String destinObj = "${destinBean}"; Class<?> srcClass = ${SrcBean}.class; String srcObj = "${srcBean}"; Method[] destinMethods = destinClass.getMethods(); Method[] srcMethods = srcClass.getMethods(); for (Method destinMethod : destinMethods) { if (destinMethod.getName().startsWith("set") && destinMethod.getParameterTypes().length == 1) { String setterName = destinMethod.getName(); String prop = setterName.substring("set".length()); if …

eclipse代码生成模板:把一个bean的属性复制到另一个bean Read More »

spring aop与aspectj到底什么关系?

首先,aspectj自己是一个完整的aop框架,没有spring也能跑起来。 其次,Spring AOP是一个专有名词。它专制一种运行机制,不是spring容器中的AOP都叫Spring AOP. Spring AOP中有很多看上去aspectj的东西,但Spring AOP在运行时,并不会触发aspectj的运行。Spring AOP是基于Proxy机制的,跟aspectj的compiler/weave机制其实没有半毛钱关系 。 虽然代码里这样声明了,但其实还是proxy-based的spring aop. <aop:aspectj-autoproxy/> 然而,Spring AOP又偏偏基本照搬了aspectj的领域概念和各种语法,并且直接使用了aspectj的相关jar库。 什么@PointCut, @Before等等,都是aspectjrt.jar中直接包括的类。官方文档说,这叫aspectj style. 引用 The @AspectJ style was introduced by the AspectJ project as part of the AspectJ 5 release. Spring interprets the same annotations as AspectJ 5, using a library supplied by AspectJ for pointcut parsing and matching. The AOP …

spring aop与aspectj到底什么关系? Read More »

写了一个excel处理工具sep4j – 一行代码完成excel的读写

sep4j – The Simple Excel Processing for Java 通过一次静态方法调用完成 excel <=> Collection<T> 的转换 Collection<T> => Excel Collection<User> users = Arrays.asList(user1, user2); LinkedHashMap<String, String> headerMap = new LinkedHashMap<String, String>(); headerMap.put("userId", "User Id"); //"userId" is a property of User class. // "User Id" will be the column header in the excel. headerMap.put("firstName", "First Name"); headerMap.put("lastName", "Last Name"); …

写了一个excel处理工具sep4j – 一行代码完成excel的读写 Read More »