首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aspose许可证对象是如何工作的?它会永远持续下去吗?

Aspose许可证对象是如何工作的?它会永远持续下去吗?
EN

Stack Overflow用户
提问于 2010-03-10 18:50:27
回答 3查看 16.3K关注 0票数 7

我正在使用Aspose来处理PDF和Word文档。每次我要对文档执行某些操作时,我都要确保调用以下代码:

代码语言:javascript
复制
Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense("Aspose.Total.lic");

Aspose.Words.License wordLicense = new Aspose.Words.License();
wordLicense.SetLicense("Aspose.Total.lic");

pdfLicensewordLicense变量从来没有在任何地方使用过,但是Aspose正确地识别出我确实有一个有效的许可证。这是怎么发生的?许可证是否被保存在某个秘密的单例中?如果是这样,这是否意味着它们会持续到线程的整个生命周期?

由于这是在web应用程序中使用的,如果我在应用程序启动时运行上面的代码,那么我可以在整个应用程序中安全地使用Aspose,而不用担心许可问题吗?

目前,我更加偏执,在使用Aspose的每个方法的开头都运行该代码。这很好用--我的许可证被正确地识别了--但是它有点太“巧合编程”了,让我感觉不舒服。

(我使用的是带有ASP.NET 3.5的C#,如果有什么不同的话。)

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-03-10 19:07:21

如果您阅读product documentation,您将看到下面这一行:

在对文档执行任何操作之前,您需要设置许可证。对于每个应用程序(或进程),只需设置一次license

因此它是以流程为中心的。

票数 7
EN

Stack Overflow用户

发布于 2012-12-04 18:46:59

在Java版本的Aspose中,您可以通过调用

代码语言:javascript
复制
License.isLicenseSet();

它返回一个布尔值。请注意,这是一个静态方法。

票数 1
EN

Stack Overflow用户

发布于 2014-06-17 09:17:00

我尝试创建一个Spring bean来执行此操作(如下所示),但它不起作用。Spring似乎想要调用License.setLicense(Reader)而不是License.setLicense(String)。我得到的错误是无法将类型为'java.lang.String‘的属性值转换为属性’license‘许可证所需的类型'java.io.Reader’。

代码语言:javascript
复制
<bean id="asposeLicense" class="com.aspose.cells.License">
    <property name="license" value="Aspose.Cells.lic" />
</bean>

然而,我得到了这个更通用的(Java)解决方案:

web.xml:

代码语言:javascript
复制
<!-- does things needing doing when application starts or stops -->
<listener>
    <listener-class>
        com.xyz.listener.ApplicationStartupListener
    </listener-class>
</listener>

ApplicationStartupListener.java (新类):

代码语言:javascript
复制
package com.xyz.listener;

import java.io.InputStream;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.aspose.cells.License;

public class ApplicationStartupListener implements ServletContextListener {
    protected final Log logger = LogFactory.getLog(getClass());

    @Override
    public void contextInitialized(ServletContextEvent event) {
    logger.info("Initializing application context...");

    try {
        // set license for Aspose.Cells (the Excel API)
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("excel/Aspose.Cells.lic");
        License license = new License();
        license.setLicense(inputStream);
        logger.info("Aspose.Cells license set? " + License.isLicenseSet());
    } catch (Exception e) {
        logger.error("Error encountered trying to set Aspose.Cells license!", e);
    }

    logger.info("Application context initialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2416216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档