写main测试肯定是不行的,因为你在web环境中,一般serviceImpl中的dao之类的数据库连接都由容器启动的时候创建好了,不会报错。但是你在main中,没有这个环境啊。可以这么写:
ApplicationContext ctx = new FileSystemXmlApplicationContext("WebContent/WEB-INF/spring/*.xml"); //创建容器类上下文
CfpanmouncementServiceImpl cfpanmouncementService= ctx.getBean("xxxxx");
List