aspose邮件与Java 11

huangapple go评论74阅读模式
英文:

aspose email with java 11

问题

我正在尝试将 Aspose Email 版本升级到 20.7,并且我正在使用 Java 11 进行项目开发,但是我遇到了以下异常。

在类路径中已经包含了 Aspose Email 的 JAR 包。

Caused by: org.springframework.beans.factory.BeanCreationException: 无法自动装配字段: private com.*
    com.* 的嵌套异常是 java.lang.NoClassDefFoundError: com/aspose/email/MailMessage
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
    ... 95 more
Caused by: java.lang.NoClassDefFoundError: com/aspose/email/MailMessage
    at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
    at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:382)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:320)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:798)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:493)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
    ... 97 more
Caused by: java.lang.ClassNotFoundException: com.aspose.email.MailMessage
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
    ... 113 more

(代码部分未翻译,仅返回翻译的内容)

英文:

I am trying to upgrade the aspose email version to 20.7 and I am using java 11 for my project, but I get these exceptions.
The aspose email jar is in the classpath.

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.*
 com.* nested exception is java.lang.NoClassDefFoundError: com/aspose/email/MailMessage
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
	... 95 more
Caused by: java.lang.NoClassDefFoundError: com/aspose/email/MailMessage
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:382)
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:320)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:798)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:493)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
	... 97 more
Caused by: java.lang.ClassNotFoundException: com.aspose.email.MailMessage
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
	... 113 more

答案1

得分: 1

如果您计划在JDK11或更高版本中使用EWSClient API,则需要添加JAXB依赖。所有其他的Aspose.Email API在没有任何额外依赖的情况下正常工作。

(JAXB API被视为Java EE API,因此在Java SE 9中不再包含在默认的类路径中。在Java 11中,它们完全从JDK中移除。在stackoverflow上描述的问题:如何解决Java 9中的java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException)

Maven JAXB依赖项:

  • javax.xml.bind jaxb-api 2.3.1
  • com.sun.xml.bind jaxb-impl 2.3.1
  • com.sun.xml.bind jaxb-core 2.3.0.1
  • com.sun.xml.messaging.saaj saaj-impl 1.5.0

也有类似的问题在以下主题中提问过。
https://forum.aspose.com/t/migrating-aspose-email-to-20-7-with-java-11/219092

英文:

If you plan to use EWSClient API with JDK11 or above, we need to add JAXB dependencies. All other Aspose.Email API works normally without any additional dependencies.

(The JAXB APIs are considered to be Java EE APIs, and therefore are no longer contained on the default class path in Java SE 9. In Java 11 they are completely removed from the JDK.
Issue described on stackoverflow: How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9 1

Maven JAXB dependencies:

  • javax.xml.bind jaxb-api 2.3.1
  • com.sun.xml.bind jaxb-impl 2.3.1
  • com.sun.xml.bind jaxb-core 2.3.0.1
  • com.sun.xml.messaging.saaj saaj-impl 1.5.0

There has been similar question asked over following thread as well.
https://forum.aspose.com/t/migrating-aspose-email-to-20-7-with-java-11/219092

答案2

得分: 0

以下是翻译好的内容:

Dependency Management 允许在不添加被所有子模块继承的依赖的情况下, consoliD争和集中管理依赖版本。当您拥有一组继承共同父模块的项目(即多个项目)时,这尤其有用。

dependencyManagement 的另一个极其重要的用途是控制传递依赖中使用的构件版本。

在父 POM 中,依赖和 dependencyManagement 之间的主要区别在于:

在依赖部分中指定的构件始终将作为子模块的依赖被包含进来。

在 dependencyManagement 部分指定的构件,仅当它们也在子模块本身的依赖部分中指定时,才会包含在子模块中。

您可以在父模块中指定版本和/或范围,而在子 POM 中可以省略它们。这可以帮助您为子模块使用统一的依赖版本,而无需在每个子模块中指定版本。

例如,父 POM 的 dependencyManagement 部分:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-email</artifactId>
            <version>${lib.email.aspose.version}</version>
            <classifier>jdk16</classifier>
        </dependency>
    </dependencies>
</dependencyManagement>

子 POM 的依赖部分:

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-email</artifactId>
        <classifier>jdk16</classifier>
    </dependency>
</dependencies>

我建议您使用 Maven 构建测试项目。我确信子模块在依赖部分中包含了 Aspose.Email 依赖。

英文:

The Dependency Management allows to consolidate and centralize the management of dependency versions without adding dependencies which are inherited by all children. This is especially useful when you have a set of projects (i.e. more than one) that inherits a common parent.

Another extremely important use case of dependencyManagement is the control of versions of artifacts used in transitive dependencies.

In the parent POM, the main difference between the dependencies and dependencyManagement is this:

Artifacts specified in the dependencies section will ALWAYS be included as a dependency of the child module(s).

Artifacts specified in the dependencyManagement section, will only be included in the child module if they were also specified in the dependencies section of the child module itself.

You specify the version and/or scope in the parent, and you can leave them out when specifying the dependencies in the child POM. This can help you use unified versions for dependencies for child modules, without specifying the version in each child module.

For example, PARENT POM dependencyManagement:

&lt;dependencyManagement&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;com.aspose&lt;/groupId&gt;
            &lt;artifactId&gt;aspose-email&lt;/artifactId&gt;
            &lt;version&gt;${lib.email.aspose.version}&lt;/version&gt;
            &lt;classifier&gt;jdk16&lt;/classifier&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;

CHILD POM dependencies:

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.aspose&lt;/groupId&gt;
        &lt;artifactId&gt;aspose-email&lt;/artifactId&gt;
        &lt;classifier&gt;jdk16&lt;/classifier&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

I suggest you to build test project with maven. I am sure that child module included Aspose.Email dependency in the dependencies section.

huangapple
  • 本文由 发表于 2020年9月25日 23:31:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64067143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定