我继续得到这个例外。
org.springframework.beans.factory.BeanCreationException: Error creating bean with nam 'mailService' defined in ServletContext resource [/WEB-INF/spring-agenttools.xml]:
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.tttt.iss.agenttools.util.MailService]: Constructor threw exception; nested exception is
java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
我已经像这样配置了这个插件。如果我从类路径中删除所有mail.jar,我的代码将无法正常工作。如果我添加它,我会得到异常
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<!--
<webApp>${basedir}/target/agenttools.war</webApp>
-->
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>30000</maxIdleTime>
<headerBufferSize>8192</headerBufferSize>
</connector>
<connector implementation="org.mortbay.jetty.security.SslSocketConnector">
<port>8443</port>
<maxIdleTime>30000</maxIdleTime>
<headerBufferSize>8192</headerBufferSize>
<keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
<password>jetty6</password>
<keyPassword>jetty6</keyPassword>
</connector>
</connectors>
<jettyEnvXml>src/main/webapp/WEB-INF/jetty-web.xml</jettyEnvXml>
<useProvided>false</useProvided>
<webAppConfig>
<defaultsDescriptor>${basedir}/src/test/resources/webdefault.xml</defaultsDescriptor>
<contextPath>/</contextPath>
<!-- Defining the extraClasspath is tricky. Please leave it on one line. Multiline works in windows but it fails in a linux environment -->
<extraClasspath>${basedir}/target/agenttools</extraClasspath>
<baseResource implementation="org.mortbay.resource.ResourceCollection">
<resourcesAsCSV>src/main/webapp</resourcesAsCSV>
</baseResource>
</webAppConfig>
<systemProperties>
<systemProperty>
<name>java.naming.factory.initial</name>
<value>org.mortbay.naming.InitialContextFactory</value>
</systemProperty>
<systemProperty>
<name>build.compiler</name>
<value>com.ttt.cs.is.ttt.jetty.JDTCompiler16</value>
</systemProperty>
<systemProperty>
<name>log4j.configuration</name>
<value>log4j-jetty.properties</value>
</systemProperty>
</systemProperties>
<stopPort>9966</stopPort>
<stopKey>halt</stopKey>
</configuration>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${activation.version}</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${mail.version}</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>serializer</artifactId>
<version>${xalan.version}</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>${xalan.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.33</version>
</dependency>
</dependencies>
</plugin>
我怎样才能使这个工作?我使用的是javax.mail:mail:1.4。与Jetty版本相同。
是否可以排除或覆盖Jetty插件邮件?
注意,mail.jar只添加一次到类路径。
更新
当我完全删除mail.jar时,应用程序启动,但我收到以下问题。所以现在我只有一个mail.Session而不是其余的。
Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.SharedByteArrayInputStream
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:242)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:379)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:341)
感谢您的帮助, Coenos
答案 0 :(得分:0)
我使用以下属性
修复了它<configuration>
<systemProperties>
<systemProperty>
<key>org.mortbay.jetty.webapp.parentLoaderPriority</key>
<value>true</value>
</systemProperty>
</systemProperties>
</configuration>