posts - 64,comments - 22,trackbacks - 0
阿里云主机推荐码,可以打九折8C0BAY 有效期 11-30号
posted @ 2015-10-15 18:13 hellxoul 阅读(177) | 评论 (0)编辑 收藏
     摘要:   阅读全文
posted @ 2015-01-05 11:52 hellxoul 阅读(287) | 评论 (0)编辑 收藏
如果不配置其他参数,大致相当于以下的配置文件(参考自org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser) 
  1 <!-- 配置路径扩展名映射的媒体类型 -->
  2   <bean name="pathExtensionContentNegotiationStrategy"
  3         class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
  4     <constructor-arg>
  5       <props>
  6         <!-- if romePresent -->
  7         <prop key="atom">application/atom+xml</prop>
  8         <prop key="rss">application/rss+xml</prop>
  9         <!-- endif -->
 10         <!-- if jackson2Present || jacksonPresent -->
 11         <prop key="json">application/json</prop>
 12         <!-- endif -->
 13         <!-- if jaxb2Present -->
 14         <prop key="xml">application/xml</prop>
 15         <!-- endif -->
 16       </props>
 17     </constructor-arg>
 18   </bean>
 19 
 20   <!-- 配置映射媒体类型的策略 -->
 21   <bean name="mvcContentNegotiationManager"
 22         class="org.springframework.web.accept.ContentNegotiationManager">
 23     <constructor-arg>
 24       <list>
 25         <ref bean="pathExtensionContentNegotiationStrategy" />
 26       </list>
 27     </constructor-arg>
 28   </bean>
 29 
 30   <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
 31     <property name="order" value="0"/>
 32     <property name="removeSemicolonContent" value="false"/>
 33     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager"/>
 34   </bean>
 35 
 36   <!-- 配置数据转换服务,默认使用格式化数据转换服务,可以对日期和数字进行格式化 -->
 37   <bean name="conversionService"
 38         class="org.springframework.format.support.DefaultFormattingConversionService">
 39     <constructor-arg index="0">
 40       <null/>
 41     </constructor-arg>
 42     <constructor-arg index="1" value="true"/>
 43   </bean>
 44 
 45   <bean name="validator"
 46         class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
 47 
 48   <!-- 配置数据绑定,通过转换服务实现绑定,如果包含jsr303实现还将进行校验 -->
 49   <bean name="webBindingInitializer"
 50         class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
 51     <property name="conversionService" ref="conversionService" />
 52     <!-- if jsr303Present -->
 53     <property name="validator" ref="validator" />
 54     <!-- endif -->
 55   </bean>
 56 
 57   <bean name="byteArrayHttpMessageConverter"
 58         class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
 59 
 60   <bean name="stringHttpMessageConverter"
 61         class="org.springframework.http.converter.StringHttpMessageConverter">
 62     <property name="writeAcceptCharset" value="false" />
 63   </bean>
 64 
 65   <bean name="resourceHttpMessageConverter"
 66         class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
 67   <bean name="sourceHttpMessageConverter"
 68         class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
 69   <bean name="allEncompassingFormHttpMessageConverter"
 70         class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/>
 71   <bean name="atomFeedHttpMessageConverter"
 72         class="org.springframework.http.converter.feed.AtomFeedHttpMessageConverter"/>
 73   <bean name="rssChannelHttpMessageConverter"
 74         class="org.springframework.http.converter.feed.RssChannelHttpMessageConverter"/>
 75   <bean name="jaxb2RootElementHttpMessageConverter"
 76         class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
 77   <bean name="mappingJacksonHttpMessageConverter"
 78         class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
 79 
 80   <!-- 配置@RequestBody,@ResponseBody注解可用的转换器 -->
 81   <util:list id="messageConverters"
 82              list-class="org.springframework.beans.factory.support.ManagedList">
 83     <ref bean="byteArrayHttpMessageConverter" />
 84     <ref bean="stringHttpMessageConverter" />
 85     <ref bean="resourceHttpMessageConverter" />
 86     <ref bean="sourceHttpMessageConverter" />
 87     <ref bean="allEncompassingFormHttpMessageConverter" />
 88     <!-- if romePresent -->
 89     <ref bean="atomFeedHttpMessageConverter" />
 90     <ref bean="rssChannelHttpMessageConverter" />
 91     <!-- endif -->
 92     <!-- if jaxb2Present -->
 93     <ref bean="jaxb2RootElementHttpMessageConverter" />
 94     <!-- endif -->
 95     <!-- if jacksonPresent -->
 96     <ref bean="mappingJacksonHttpMessageConverter" />
 97     <!-- endif -->
 98   </util:list>
 99 
100   <!-- 将任意类型的Controller适配为Handler -->
101   <bean name="requestMappingHandlerAdapter"
102         class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
103     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
104     <property name="webBindingInitializer" ref="webBindingInitializer" />
105     <property name="messageConverters" ref="messageConverters" />
106   </bean>
107 
108   <!-- 这个拦截器暴露转换器服务让spring:bind和spring:eval标签可用 -->
109   <bean name="csInterceptor"
110         class="org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor">
111     <constructor-arg index="0" ref="conversionService"/>
112   </bean>
113 
114   <!-- 现在所有拦截器都必须设定响应的路径映射 -->
115   <bean name="mappedCsInterceptor"
116         class="org.springframework.web.servlet.handler.MappedInterceptor">
117     <constructor-arg index="0">
118       <null/>
119     </constructor-arg>
120     <constructor-arg index="1" ref="csInterceptor"/>
121   </bean>
122 
123   <!-- 使用@ExceptionHandler注解的方法来处理Exception,优先级为0(最高) -->
124   <bean name="exceptionHandlerExceptionResolver"
125         class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver">
126     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
127     <property name="messageConverters" ref="messageConverters" />
128     <property name="order" value="0" />
129   </bean>
130 
131   <!-- 如果抛出的Exception类带有@ResponseStatus注解,响应返回该注解的Http状态码,优先级为1 -->
132   <bean name="responseStatusExceptionResolver"
133         class="org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver">
134     <property name="order" value="1" />
135   </bean>
136 
137   <!-- SpringMvc内部异常处理 -->
138   <bean name="defaultExceptionResolver"
139         class="org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver">
140     <property name="order" value="2" />
141   </bean>
142 
posted @ 2014-08-03 22:35 hellxoul 阅读(2876) | 评论 (1)编辑 收藏
HeadFirst Servlet/JSP 学习笔记
1.容器加载类,调用servlet的无参构造方法,并调用servlet的init()方法,从而初始化servlet。
2.init()在servlet一生中只调用一次,往往在servlet为客户请求提供服务之前调用。
3.init()方法使servlet可以访问ServletConfig和ServletContext对象,servlet需要从这些对象得到有关servlet配置和web应用的信息。
4.容器通过调用servlet的destroy()方法来结束servlet的生命
5.servlet一生的大多时间都是在为某个客户端请求运行service()方法
6.对servlet的每个请求都在一个单独的线程中运行,任何特定servlet类都只有一个实例。
posted @ 2014-07-05 15:21 hellxoul 阅读(253) | 评论 (0)编辑 收藏
转自:http://www.cnblogs.com/peida/p/Guava_Ordering.html

Ordering是Guava类库提供的一个犀利强大的比较器工具,Guava的Ordering和JDK Comparator相比功能更强。它非常容易扩展,可以轻松构造复杂的comparator,然后用在容器的比较、排序等操作中。

  本质上来说,Ordering 实例无非就是一个特殊的Comparator 实例。Ordering只是需要依赖于一个比较器(例如,Collections.max)的方法,并使其可作为实例方法。另外,Ordering提供了链式方法调用和加强现有的比较器。

  下面我们看看Ordering中的一些具体方法和简单的使用实例。

  常见的静态方法:

  natural():使用Comparable类型的自然顺序, 例如:整数从小到大,字符串是按字典顺序;
  usingToString() :使用toString()返回的字符串按字典顺序进行排序;
  arbitrary() :返回一个所有对象的任意顺序, 即compare(a, b) == 0 就是 a == b (identity equality)。 本身的排序是没有任何含义, 但是在VM的生命周期是一个常量。

  简单实例:

复制代码
import java.util.List;
import org.junit.Test;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;

public class OrderingTest {

    @Test
    public void testStaticOrdering(){
        List<String> list = Lists.newArrayList();
        list.add("peida");
        list.add("jerry");
        list.add("harry");
        list.add("eva");
        list.add("jhon");
        list.add("neron");
        
        System.out.println("list:"+ list);
Ordering
<String> naturalOrdering = Ordering.natural(); Ordering<Object> usingToStringOrdering = Ordering.usingToString(); Ordering<Object> arbitraryOrdering = Ordering.arbitrary(); System.out.println("naturalOrdering:"+ naturalOrdering.sortedCopy(list)); System.out.println("usingToStringOrdering:"+ usingToStringOrdering.sortedCopy(list)); System.out.println("arbitraryOrdering:"+ arbitraryOrdering.sortedCopy(list)); } }
复制代码

  输出:

list:[peida, jerry, harry, eva, jhon, neron]
naturalOrdering:[eva, harry, jerry, jhon, neron, peida]
usingToStringOrdering:[eva, harry, jerry, jhon, neron, peida]
arbitraryOrdering:[neron, harry, eva, jerry, peida, jhon]

  操作方法:

  reverse(): 返回与当前Ordering相反的排序:
  nullsFirst(): 返回一个将null放在non-null元素之前的Ordering,其他的和原始的Ordering一样;
  nullsLast():返回一个将null放在non-null元素之后的Ordering,其他的和原始的Ordering一样;
  compound(Comparator):返回一个使用Comparator的Ordering,Comparator作为第二排序元素,例如对bug列表进行排序,先根据bug的级别,再根据优先级进行排序;
  lexicographical():返回一个按照字典元素迭代的Ordering;
  onResultOf(Function):将function应用在各个元素上之后, 在使用原始ordering进行排序;
  greatestOf(Iterable iterable, int k):返回指定的第k个可迭代的最大的元素,按照这个从最大到最小的顺序。是不稳定的。
  leastOf(Iterable<E> iterable,int k):返回指定的第k个可迭代的最小的元素,按照这个从最小到最大的顺序。是不稳定的。
  isOrdered(Iterable):是否有序,Iterable不能少于2个元素。
  isStrictlyOrdered(Iterable):是否严格有序。请注意,Iterable不能少于两个元素。
  sortedCopy(Iterable):返回指定的元素作为一个列表的排序副本。

复制代码
package com.peidasoft.guava.base;

import java.util.List;

import org.junit.Test;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;

public class OrderingTest {
    
    @Test
    public void testOrdering(){
        List<String> list = Lists.newArrayList();
        list.add("peida");
        list.add("jerry");
        list.add("harry");
        list.add("eva");
        list.add("jhon");
        list.add("neron");
        
        System.out.println("list:"+ list);
        
        Ordering<String> naturalOrdering = Ordering.natural();
        System.out.println("naturalOrdering:"+ naturalOrdering.sortedCopy(list));    

        List<Integer> listReduce= Lists.newArrayList();
        for(int i=9;i>0;i--){
            listReduce.add(i);
        }
        
        List<Integer> listtest= Lists.newArrayList();
        listtest.add(1);
        listtest.add(1);
        listtest.add(1);
        listtest.add(2);
        
        
        Ordering<Integer> naturalIntReduceOrdering = Ordering.natural();
        
        System.out.println("listtest:"+ listtest);
        System.out.println(naturalIntReduceOrdering.isOrdered(listtest));
        System.out.println(naturalIntReduceOrdering.isStrictlyOrdered(listtest));
        
        
        System.out.println("naturalIntReduceOrdering:"+ naturalIntReduceOrdering.sortedCopy(listReduce));
        System.out.println("listReduce:"+ listReduce);
        
        
        System.out.println(naturalIntReduceOrdering.isOrdered(naturalIntReduceOrdering.sortedCopy(listReduce)));
        System.out.println(naturalIntReduceOrdering.isStrictlyOrdered(naturalIntReduceOrdering.sortedCopy(listReduce)));
        

        Ordering<String> natural = Ordering.natural();
              
        List<String> abc = ImmutableList.of("a", "b", "c");
        System.out.println(natural.isOrdered(abc));
        System.out.println(natural.isStrictlyOrdered(abc));
        
        System.out.println("isOrdered reverse :"+ natural.reverse().isOrdered(abc));
 
        List<String> cba = ImmutableList.of("c", "b", "a");
        System.out.println(natural.isOrdered(cba));
        System.out.println(natural.isStrictlyOrdered(cba));
        System.out.println(cba = natural.sortedCopy(cba));
        
        System.out.println("max:"+natural.max(cba));
        System.out.println("min:"+natural.min(cba));
        
        System.out.println("leastOf:"+natural.leastOf(cba, 2));
        System.out.println("naturalOrdering:"+ naturalOrdering.sortedCopy(list));    
        System.out.println("leastOf list:"+naturalOrdering.leastOf(list, 3));
        System.out.println("greatestOf:"+naturalOrdering.greatestOf(list, 3));
        System.out.println("reverse list :"+ naturalOrdering.reverse().sortedCopy(list));    
        System.out.println("isOrdered list :"+ naturalOrdering.isOrdered(list));
        System.out.println("isOrdered list :"+ naturalOrdering.reverse().isOrdered(list));
        list.add(null);
        System.out.println(" add null list:"+list);
        System.out.println("nullsFirst list :"+ naturalOrdering.nullsFirst().sortedCopy(list));
        System.out.println("nullsLast list :"+ naturalOrdering.nullsLast().sortedCopy(list));
    }

}

//============输出==============
list:[peida, jerry, harry, eva, jhon, neron]
naturalOrdering:[eva, harry, jerry, jhon, neron, peida]
listtest:[1, 1, 1, 2]
true
false
naturalIntReduceOrdering:[1, 2, 3, 4, 5, 6, 7, 8, 9]
listReduce:[9, 8, 7, 6, 5, 4, 3, 2, 1]
true
true
true
true
isOrdered reverse :false
false
false
[a, b, c]
max:c
min:a
leastOf:[a, b]
naturalOrdering:[eva, harry, jerry, jhon, neron, peida]
leastOf list:[eva, harry, jerry]
greatestOf:[peida, neron, jhon]
reverse list :[peida, neron, jhon, jerry, harry, eva]
isOrdered list :false
isOrdered list :false
 add null list:[peida, jerry, harry, eva, jhon, neron, null]
nullsFirst list :[null, eva, harry, jerry, jhon, neron, peida]
nullsLast list :[eva, harry, jerry, jhon, neron, peida, null]
复制代码

posted @ 2014-07-03 10:48 hellxoul 阅读(274) | 评论 (0)编辑 收藏
     摘要: centos 6.5 安装rabbitmq  阅读全文
posted @ 2014-06-25 22:23 hellxoul 阅读(2235) | 评论 (0)编辑 收藏