下面针对在编写有关邮件发送的程序过程中的报错解决方案做下归纳
第一种
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'freeMarker' defined in class path resource [applicationContext-html.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext
.......
解决方案:添加servlet.jar包
第二种
org.springframework.mail.MailSendException; nested exception details (1) are:
Failed message 1:
com.sun.mail.smtp.SMTPSendFailedException: 553 You are not authorized to send mail, authentication is required
解决方案:检查程序中的邮件发送者是否与Spring配置文件中配置的一致,不一致改成一致即可
第三种
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSender' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
解决方案:添加mail.jar
第四种
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceFacade' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy
java.lang.ClassCastException: $Proxy4 cannot be cast to com.javacrazyer.comon.ServiceFacade
at com.javacrazyer.service.test.UserServiceTest.test(UserServiceTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
解决方案:1)将Spring配置中id为serviceFacade的类改成实现某接口的类
2)添加CGLIB的jar包
这个就可以证明AOP的底层原理是动态代理
第五种
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
解决方案:
JavaEE版本和JavaMail的版本不一致,请将sun公司上下载最新版本.
例如:javaMail 1.3以下的如果在javaEE5上就会出现上面的错误,
但如果在javaEE1.4下就正常.(但本人试过,javaEE5+javaMail1.4还是有一样的问题)
因为javaEE5中包含有javaMail的类但是却不全面,所以出本身的JavaMail
包冲突.
第六种
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer] for bean with name 'freeMarker' defined in class path resource [applicationContext-html.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
解决方案:添加spring-webmvc好多人都不知道org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer这个类到底在哪个jar里面所以找了半天都没找到,这里我说明下确切位置:
spring-framework-2.5.6\dist\modules\spring-webmvc.jar
servlet.jar和mail.jar上网下载的话好多都扣分,我就贡献出来吧,下边有下载