2007年12月25日

在使用Spring相关产品时,你可能会碰到下面这种异常:
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
这是异常的第一行,按以往的经验,第一行应该就是问题所在,但是实际上,从这行来看你根本不知道错在哪里。

后面接下来的是:
Error creating bean with name 'basicProcessingFilter'
Cannot resolve reference to bean 'authenticationManager'
while setting bean property 'authenticationManager';

nested exception is Error creating bean with name 'authenticationManager'
Cannot resolve reference to bean 'casAuthenticationProvider'
while setting bean property 'providers' with key [0];

nested exception is : Error creating bean with name 'casAuthenticationProvider'
Cannot resolve reference to bean 'statelessTicketCache'
while setting bean property 'statelessTicketCache';

nested exception is: Error creating bean with name 'statelessTicketCache'
Error setting property values;

nested exception is
nested PropertyAccessExceptions (1) are:
PropertyAccessException 1:
TypeMismatchException:

Failed to convert property value of type [net.sf.ehcache.Cache]
to required type [net.sf.ehcache.Ehcache] for property 'cache'

Error creating bean with name 'authenticationManager'
Cannot resolve reference to bean 'casAuthenticationProvider'
while setting bean property 'providers' with key [0];

nested exception is
Error creating bean with name 'casAuthenticationProvider'
Cannot resolve reference to bean 'statelessTicketCache' while setting bean property 'statelessTicketCache';

nested exception is
Error creating bean with name 'statelessTicketCache'
Error setting property values;

nested exception is
nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException:
Failed to convert property value of type [net.sf.ehcache.Cache]
to required type [net.sf.ehcache.Ehcache] for property 'cache'

Error creating bean with name 'casAuthenticationProvider'
Cannot resolve reference to bean 'statelessTicketCache'
while setting bean property 'statelessTicketCache';

nested exception is
Error creating bean with name 'statelessTicketCache'
Error setting property values;

nested exception is PropertyAccessExceptionsException;
nested PropertyAccessExceptions (1) are:
PropertyAccessException 1:TypeMismatchException:
Failed to convert property value of type [net.sf.ehcache.Cache]
to required type [net.sf.ehcache.Ehcache] for property 'cache'

Error creating bean with name 'statelessTicketCache'
Error setting property values;

nested exception is PropertyAccessExceptionsException;
nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException:
Failed to convert property value of type [net.sf.ehcache.Cache]
to required type [net.sf.ehcache.Ehcache] for property 'cache'

PropertyAccessExceptionsException;
nested PropertyAccessException details (1) are:
PropertyAccessException 1:
ypeMismatchException:
Failed to convert property value of type [net.sf.ehcache.Cache]
to required type [net.sf.ehcache.Ehcache] for property 'cache'

上面的内容是我将重复信息去掉,并分块后的结果。

从报错机制可以看出来,spring出现异常不同于普通的java异常,我们查异常的习惯一般是关注第一行,但是sping恰恰相反,要在sping中查错,你必须分解他,因为spring的嵌套层次比较多,它报错是从最高层报起,然后逐层往下,每个层次都会要报错,直到最终出错的地方,因此查sping的错必须逐层分解到最底层,那里才是真正出错的地方。

OK,现在看出来了,真正错误的原因是:
Failed to convert property value of type [net.sf.ehcache.Cache]
to required type [net.sf.ehcache.Ehcache] for property 'cache'

我出现这个错误的原因是使用了Acegi 1.0.5,它本身自带了ehcache 1.2.4.jar
但是我同时还使用了hibernate3.1,从Eclipse导入hibernate3.1时,将会导入ehcache 1.1.jar,因为hibernate本身也要使用EHCache,但是版本不同。

posted @ 2007-12-25 10:02 Exiler 阅读(3189) | 评论 (0)编辑 收藏


2007年12月24日

公司做了套由JMS做消息队列,从JMS取出对象后转交给RTX服务器发送RTX消息的机制。
前几天出现重大BUG:消息不发送。

经过两天的测试发现了症结所在:
我们通过RTX服务器发送RTX消息的机制是通过向一个URL后面加参数来实现的,而这个请求URL,在RTX服务器上默认超时时间设置为0,即永不超时,同时此服务器设置的同一个连接两次发送消息的最短间隔时间为15毫秒。
因为我们网管的失误,打开了8012端口,此端口为RTX服务器接收消息的端口,致使开发环境中的消息能够发送到工作环境的服务器,使得RTX服务器接收的并发量出现瞬时过大现象,RTX服务器判断为DDOS攻击,因此拒绝服务,此服务器拒绝服务的方式为不返回任何值。
同时,因为设置的超时时间为0,因此后继的消息因为前面的并未抛出超时异常也未发送完成,所以积压在JMS队列中,造成了消息发送失败的现象。

一开始我一直在找JMS的原因,因为曾经在某处看到过JMS服务器并不稳定的文章,但是我在测试过程中发现,JMS还是很强大的,在消息积压的时候,其队列中最高曾积压了4000多条消息,仍然能够继续工作,我使用的是ActiveMQ+Tomcat6.10。

希望能给碰到类似JMS消息积压现象的朋友一点启示,从JMS消息不能正常取出入手,或许会有收获!

posted @ 2007-12-24 09:33 Exiler 阅读(3812) | 评论 (5)编辑 收藏


2007年12月9日

类似Hibernate异常:
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Could not read mappings from resource:
这种错误出现的情况只有在人为改动了Hibernate生成的文件的时候出现。

情况有两种
1:hibernate.cfg.xml中,属性<mapping resource="./Permission.hbm.xml" />里面"./Permission.hbm.xml"所指定的路径不正确,即改动了生成实体的配置文件的位置。
2:Permission.hbm.xml中,<class name="db_DAO.Permission" table="ACEGI_PERMISSION" schema="POSTTEST">其中属性class name="db_DAO.Permission"指定的Permission类名错误,即:改动了生成实体类的类名或者包名。

如果上述两种情况改动后仍然报错,clean一下项目后OK

posted @ 2007-12-09 15:08 Exiler 阅读(8511) | 评论 (4)编辑 收藏


2007年4月21日

/**
 * @author Solo
 *
 * 很久以前写的一道题目,昨天翻出来看了看,都有些忘记了,花了1个小时补上了注释
 * 对于学习在Java中使用正则表达式有点帮助
 * 将一个保存有ip地址与地区对照关系的文本文件导入到数据库时,
 * 应该将其中的某些空格替换成逗号(,),即对于如下格式的文本文件内容:
 * 起始IP 结束IP 地区
 * ---------------------------------------------------------------
 * 61.54.231.245 61.54.231.245 河南省安阳市 新世纪网吧
 * 61.54.231.246 61.54.231.246 河南省安阳市 未知地区
 * 61.54.231.9 61.54.231.247 河南省安阳市 红日网吧
 * 61.54.231.248 61.54.231.248 河南省安阳市 安阳师范学院
 * 61.54.231.249 61.54.231.249 河南省安阳市 黑蜘蛛网吧(师范学院附近)
 * 应转换成下面的这种格式:
 * 61.54.231.245,61.54.231.245,河南省安阳市 新世纪网吧
 * 61.54.231.246,61.54.231.246,河南省安阳市 未知地区
 * 61.54.231.247,61.54.231.247,河南省安阳市 红日网吧
 * 61.54.231.248,61.54.231.248,河南省安阳市 安阳师范学院
 * 61.54.231.249,61.54.231.249,河南省安阳市 黑蜘蛛网吧(师范学院附近)
 * 任务:
 * 阅读String.replaceAll方法的帮助,以及它提供的相关超链接,
 * 了解该方法的用法后,编写一个java程序来自动实现上面的正则表达式替换,
 * 将a.txt替换后的结果保存到b.txt文件中。
 * 另外,我们在实现ip地区查询系统时,使用的是类似如下的sql语法:
 * select 地区 from ip表 where 用户ip>起始IP and 用户ip<结束ip
 * 通过这条sql语句就可以查询出用户ip所对应的地区结果。由于用户ip与起始
 * ip和结束ip的比较属于字符串比较,如果用户ip为9.1.1.1,那么它与
 * 61.54.231.245比较的结果就是前者大于后者,因为用户ip的第一个字符“9”
 * 大于61.54.231.245中的第一个字符“6”。
 * 现在请你想出一种解决办法,让上面的sql语句能够返回正确结果。
 * 请按这种思路在你的程序中增加进行这种改变的正则表达式替换。
 */

import java.io.*;
import java.util.regex.*;

public class Ip
{
    private static void fileIO(File f)
    {
        String strLine;
       
        // 调用执行本程序的操作系统的标准换行符,意味着跨平台
        String line = System.getProperty("line.separator");
        try
        {
            // 输入流
            FileInputStream fis = new FileInputStream(f);
            InputStreamReader isr = new InputStreamReader(fis);
            BufferedReader br = new BufferedReader(isr);
           
            // 输出流
            FileOutputStream fos = new FileOutputStream("c://b.txt");
            OutputStreamWriter osw = new OutputStreamWriter(fos);
            BufferedWriter bw = new BufferedWriter(osw);
           
            /*
             * 创建一个模式对象, 模式中编辑的正则表达式匹配分别是(200-249|250-255|001-199) 以匹配一个IP地址
             */
            Pattern pattern = Pattern
                    .compile("((2[0-4]d|25[0-5]|[01]?dd?).){3}(2[0-4]d|25[0-5]|[01]?dd?)");
           
            // 声明模式适配器
            Matcher matcher;
           
            // 循环读取文件中的每一行
            while ((strLine = br.readLine()) != null)
            {
                /*
                 * String调用replaceAll方法匹配一个正则表达式找到一个位置,然后替换成逗号
                 */
                strLine = strLine.replaceAll("(?<=d)s+", ",");
                
                // 用适配器加载一行字符串,并匹配模式
                matcher = pattern.matcher(strLine);
               
                // 如果在一行中能找到匹配的字符串则循环
                while (matcher.find())
                {
                    // 取一行中第一个能匹配的子字符串
                    String buf = matcher.group();
                   
                    // 以"."分割成数字,然后分别补零,再合并
                    strLine = matcher.replaceAll(change(buf));
                  
                    // 输入一行到文件,但不包括换行符
                    bw.write(strLine);
                   
                    // 输入行分割符,即换行符
                    bw.write(line);
                }
            }
           
            // 关闭输入流
            br.close();
           
            // 关闭输出流
            bw.close();
        }
        // 捕获原始文件未找到异常
        catch (FileNotFoundException e)
        {
            System.out.println("原始文件未找到");
        }
        // 捕获IO异常
        catch (IOException e)
        {
            e.printStackTrace();
        }

    }
   
    // 此方法用来接收一个分割出来的一个数字,将不足3位的补零后返回
    private static String fill(String str)
    {
        // 不足3位的补零
        while (str.length() < 3)
        {
            str = '0' + str;
        }
       
        // 返回补零后的字符串
        return str;
    }
   
    private static String change(String buf)
    {
        // 缓冲字符串
        String temp;
       
        // 结果返回字符串
        String ret;
       
        // 以"."分割,存入字符串数组
        String[] str = buf.split(".");
       
        // 第一个数字不需要在前面加"."
        ret = fill(str[0]);
       
        // 从第2个数字开始,给每个数字前面分别再加上".",并且不足的补零
        for (int i = 1; i < str.length; i++)
        {
            // 调用fill方法给不足3位的数字补零
            temp = fill(str[i]);
           
            // 每个数字加点后从新组装成一个
            ret = ret + "." + temp;
        }
        // 返回结果字符串
        return ret;
    }
   
    // 程序入口
    public static void main(String[] args)
    {
        // 读原始文件
        File f = new File("c://a.txt");
       
        // 将原始文件传入fileIO方法,按要求加工
        fileIO(f);
    }
}

posted @ 2007-04-21 01:21 Exiler 阅读(1123) | 评论 (0)编辑 收藏


仅列出标题  

posts - 3, comments - 32, trackbacks - 0, articles - 3

Copyright © Exiler