<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:flex="http://www.springframework.org/schema/flex"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">java
<!--驗證碼服務 -->
<bean id="captchaService"
class="com.octo.captcha.service.multitype.GenericManageableCaptchaService">
<constructor-arg index="0" ref="imageEngine" />
<constructor-arg type="int" index="1" value="180" /> <!--有效期300秒 -->
<constructor-arg type="int" index="2" value="100000" />
</bean>spring
<!-- 圖片引擎 -->
<bean id="imageEngine" class="com.octo.captcha.engine.GenericCaptchaEngine">
<constructor-arg index="0">
<list>
<ref bean="captchaFactory" />
</list>
</constructor-arg>
</bean>dom
<bean id="captchaFactory" class="com.octo.captcha.image.gimpy.GimpyFactory">
<constructor-arg>
<ref bean="wordgen" />
</constructor-arg>
<constructor-arg>
<ref bean="wordtoimage" />
</constructor-arg>
</bean>字體
<bean id="wordgen"
class="com.octo.captcha.component.word.wordgenerator.RandomWordGenerator">
<!--可選字符 -->
<constructor-arg>
<value>
0123456789ABCDEFGHIJKLNMOPQRSTUVWXYZ
</value>
</constructor-arg>
</bean>flex
<bean id="wordtoimage"
class="com.octo.captcha.component.image.wordtoimage.ComposedWordToImage">
<constructor-arg index="0">
<ref bean="fontGenRandom" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="backGenUni" />
</constructor-arg>
<constructor-arg index="2">
<ref bean="decoratedPaster" />
</constructor-arg>
</bean>component
<bean id="fontGenRandom"
class="com.octo.captcha.component.image.fontgenerator.RandomFontGenerator">
<!--最小字體 -->
<constructor-arg index="0">
<value>20</value>
</constructor-arg>
<!--最大字體 -->
<constructor-arg index="1">
<value>26</value>
</constructor-arg>
<constructor-arg index="2">
<list>
<bean class="java.awt.Font">
<constructor-arg index="0">
<value>Arial</value>
</constructor-arg>
<constructor-arg index="1">
<value>0</value>
</constructor-arg>
<constructor-arg index="2">
<value>10</value>
</constructor-arg>
</bean>
<bean class="java.awt.Font">
<constructor-arg index="0">
<value>Tahoma</value>
</constructor-arg>
<constructor-arg index="1">
<value>0</value>
</constructor-arg>
<constructor-arg index="2">
<value>10</value>
</constructor-arg>
</bean>
</list>
</constructor-arg>
</bean>xml
<bean id="backGenUni"
class="com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator">
<!--背景寬度 -->
<constructor-arg index="0">
<value>100</value>
</constructor-arg>
<!--背景高度 -->
<constructor-arg index="1">
<value>40</value>
</constructor-arg>
</bean>圖片
<bean id="decoratedPaster"
class="com.octo.captcha.component.image.textpaster.DecoratedRandomTextPaster">
<!--最大字符長度 -->
<constructor-arg type="java.lang.Integer" index="0">
<value>6</value>
</constructor-arg>
<!--最小字符長度 -->
<constructor-arg type="java.lang.Integer" index="1">
<value>6</value>
</constructor-arg>
<!--文本顏色 -->
<constructor-arg index="2">
<ref bean="colorGen" />
</constructor-arg>
<!--文本混淆 -->
<constructor-arg index="3">
<list>
<!-- <ref bean="baffleDecorator"/> -->
</list>
</constructor-arg>
</bean>generator
<bean id="baffleDecorator"
class="com.octo.captcha.component.image.textpaster.textdecorator.BaffleTextDecorator">
<constructor-arg type="java.lang.Integer" index="0">
<value>1</value>
</constructor-arg>
<constructor-arg type="java.awt.Color" index="1">
<ref bean="colorWrite" />
</constructor-arg>
</bean>it
<bean id="colorGen"
class="com.octo.captcha.component.image.color.SingleColorGenerator">
<constructor-arg type="java.awt.Color" index="0">
<ref bean="colorDimGrey" />
</constructor-arg>
</bean>
<bean id="colorWrite" class="java.awt.Color">
<constructor-arg type="int" index="0">
<value>12</value>
</constructor-arg>
<constructor-arg type="int" index="1">
<value>55</value>
</constructor-arg>
<constructor-arg type="int" index="2">
<value>25</value>
</constructor-arg>
</bean>
<bean id="colorDimGrey" class="java.awt.Color">
<constructor-arg type="int" index="0">
<value>123</value>
</constructor-arg>
<constructor-arg type="int" index="1">
<value>29</value>
</constructor-arg>
<constructor-arg type="int" index="2">
<value>0</value>
</constructor-arg>
</bean>
</beans>
明明最小長度驗證碼是6位, 最大長度驗證碼也是6位,可是產生驗證碼的時候爲何會出現四位,五位那麼奇怪的現象呢?由於Spring腦殘的解析機制啊。
<value>
0123456789ABCDEFGHIJKLNMOPQRSTUVWXYZ
</value>
改爲
<value>0123456789ABCDEFGHIJKLNMOPQRSTUVWXYZ</value>
這麼改一改就好了哦。上網百度一下這個問題發現好多人在問呢,結果沒有人回答。這裏我就放上解決方案和緣由吧。誰叫我那麼善良美麗呢。哦呵呵呵