2015-10-20 51 views
1

grails無法創建bean。創建名爲'mailSender'的bean的錯誤grails

這是我的config.groovy郵件。

grails { 
    mail { 
     grails.mail.jndiName = "java:comp/env/mail/mailSession" 
    } 
} 

,這是郵件/郵件會話JNDI在context.xml中

<Resource name="mail/mailSession" 
        auth="Container" 
       type="javax.mail.Session" 
       mail.smtp.host="smtp.gmail.com" 
       mail.smtp.port="465" 
       mail.smtp.auth="true" 
       mail.smtp.user="[email protected]" 
       password="abc123" 
       mail.smtp.starttls.enable="true" 
       mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory" 
    /> 

使用IAM的Tomcat 7和我把戰爭文件websapp/ROOT.war

,這是一個錯誤當我嘗試運行它時會得到什麼。

Oct 20, 2015 1:40:13 PM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSender': Cannot resolve reference to bean 'mailSession' while setting bean property 'session'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSession': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/Authenticator 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
     at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:126) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) 
     at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:153) 
     at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:170) 
     at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:127) 
     at org.codehaus.groovy.grails.web.context.GrailsConfigUtils.configureWebApplicationContext(GrailsConfigUtils.java:121) 
     at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:104) 
     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 
     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5003) 
     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517) 
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) 
     at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095) 
     at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930) 
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSession': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/Authenticator 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
     at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:126) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322) 
     ... 32 more 
Caused by: java.lang.NoClassDefFoundError: javax/mail/Authenticator 
     at org.apache.naming.factory.MailSessionFactory.getObjectInstance(MailSessionFactory.java:104) 
     at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:141) 
     at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:842) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:153) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:830) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:153) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:830) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:153) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:830) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:167) 
     at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156) 
     at javax.naming.InitialContext.lookup(InitialContext.java:411) 
     at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) 
     at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) 
     at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) 
     at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) 
     at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) 
     at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) 
     at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201) 
     at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) 
     ... 40 more 
Caused by: java.lang.ClassNotFoundException: javax.mail.Authenticator 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
     at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
     ... 63 more 

Oct 20, 2015 1:40:13 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file 
Oct 20, 2015 1:40:13 PM org.apache.catalina.session.StandardManager doLoad 
FINE: Start: Loading persisted sessions 
Oct 20, 2015 1:40:13 PM org.apache.catalina.session.StandardManager doLoad 
FINE: Loading persisted sessions from SESSIONS.ser 
Oct 20, 2015 1:40:13 PM org.apache.catalina.session.StandardManager doLoad 
FINE: No persisted data file found 
Oct 20, 2015 1:40:13 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Context [] startup failed due to previous errors 
Oct 20, 2015 1:40:13 PM org.apache.catalina.core.StandardContext filterStop 
FINE: Stopping filters 
Oct 20, 2015 1:40:13 PM org.apache.catalina.session.StandardManager stopInternal 
FINE: Stopping 
Oct 20, 2015 1:40:13 PM org.apache.catalina.session.StandardManager doUnload 
FINE: Unloading persisted sessions 
Oct 20, 2015 1:40:13 PM org.apache.catalina.session.StandardManager doUnload 
FINE: No persisted sessions to unload 
Oct 20, 2015 1:40:14 PM org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
Oct 20, 2015 1:40:14 PM org.apache.catalina.startup.HostConfig deployWAR 
INFO: Deployment of web application archive /root/tomcat7/webapps/ROOT.war has finished in 59,132 ms 
Oct 20, 2015 1:40:14 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-80"] 
Oct 20, 2015 1:40:14 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Oct 20, 2015 1:40:14 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 59307 ms 

我該如何解決這個問題?

我已經把mail.jar移動,mysq連接器和activation.jar到lib..like這個

enter image description here

這是新的錯誤..

Configuring event listener class '[email protected]' 
Oct 20, 2015 4:47:44 PM org.apache.catalina.core.StandardContext listenerStart 
FINE: Sending application start events 
log4j:WARN No appenders could be found for logger (org.codehaus.groovy.grails.commons.cfg.ConfigurationHelper). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 
Oct 20, 2015 4:47:47 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
2015-10-20 16:47:49,595 [localhost-startStop-1] ERROR context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError 
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.ExceptionInInitializerError 
     at java.lang.Class.forName(Class.java:274) 
     ... 5 more 
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{}' with class 'groovy.util.ConfigObject' to class 'int' 
     at CorporateUserService.<clinit>(CorporateUserService.groovy:31) 
     ... 6 more 
Oct 20, 2015 4:47:49 PM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError 
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.ExceptionInInitializerError 
     at java.lang.Class.forName(Class.java:274) 
     ... 5 more 
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{}' with class 'groovy.util.ConfigObject' to class 'int' 
     at CorporateUserService.<clinit>(CorporateUserService.groovy:31) 
     ... 6 more 

Oct 20, 2015 4:47:49 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file 
Oct 20, 2015 4:47:49 PM org.apache.catalina.session.StandardManager doLoad 
FINE: Start: Loading persisted sessions 
Oct 20, 2015 4:47:49 PM org.apache.catalina.session.StandardManager doLoad 
FINE: Loading persisted sessions from SESSIONS.ser 
Oct 20, 2015 4:47:49 PM org.apache.catalina.session.StandardManager doLoad 
FINE: No persisted data file found 
Oct 20, 2015 4:47:49 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Context [] startup failed due to previous errors 
Oct 20, 2015 4:47:49 PM org.apache.catalina.core.StandardContext filterStop 
FINE: Stopping filters 
Oct 20, 2015 4:47:49 PM org.apache.catalina.session.StandardManager stopInternal 
FINE: Stopping 
Oct 20, 2015 4:47:49 PM org.apache.catalina.session.StandardManager doUnload 
FINE: Unloading persisted sessions 
Oct 20, 2015 4:47:49 PM org.apache.catalina.session.StandardManager doUnload 
FINE: No persisted sessions to unload 
Oct 20, 2015 4:47:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 
SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
Oct 20, 2015 4:47:49 PM org.apache.catalina.startup.HostConfig deployWAR 
INFO: Deployment of web application archive /root/tomcat7/webapps/ROOT.war has finished in 29,869 ms 
Oct 20, 2015 4:47:49 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-bio-80"] 
Oct 20, 2015 4:47:49 PM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-bio-8009"] 
Oct 20, 2015 4:47:49 PM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 30090 ms 
+1

有你添加的Java郵件到類路徑?例外說沒有 –

+0

不......你的意思是setenv.sh?怎麼樣? – akiong

+0

@tim_yates,但我看到在WEB-INF/lib/mail.jar中的mai.jar – akiong

回答

2

的錯誤是很清楚:java.lang.ClassNotFoundException: javax.mail.Authenticator。由於javax.mail.Authenticator不見了,您必須添加activation.jar這是包含此課程的圖書館,您可以從here下載並加入您的WEB-INF/lib

如果您使用gradle構建您的項目,它將爲您解決此依賴關係,只需添加javax.mail,因爲activation是它的依賴項。在使用這解決了所需的依賴gradle這個簡單:

dependencies { 
    compile group: 'javax.mail', name: 'mail', version: '1.4.1' 
} 

而且似乎這1.4.1javax.mail新版本沒有此相關性,所以不是使用javax.mail 1.4.1javax.activation 1.1,你可以簡單地使用像1.5的新javax.mail。 4這似乎是最後的穩定版本,你可以從here

希望它能幫助下載,

+0

看到我的編輯帖子,我試圖將mail.jar和activation.jar複製到tomcat/websapp/ROOT/WEB-INF/lib – akiong

+0

但有激活1.1.jar,郵件1.4.1.jar和郵件1.4.3.jar ..爲什麼這兩種mail.jar? – akiong

+0

你只需要每個...扔在同一個文件夾中的罐子可能是你的問題的原因 –

相關問題