我正在使用Aspose来处理PDF和Word文档。每次我要对文档执行某些操作时,我都要确保调用以下代码:
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");pdfLicense和wordLicense变量从来没有在任何地方使用过,但是Aspose正确地识别出我确实有一个有效的许可证。这是怎么发生的?许可证是否被保存在某个秘密的单例中?如果是这样,这是否意味着它们会持续到线程的整个生命周期?
由于这是在web应用程序中使用的,如果我在应用程序启动时运行上面的代码,那么我可以在整个应用程序中安全地使用Aspose,而不用担心许可问题吗?
目前,我更加偏执,在使用Aspose的每个方法的开头都运行该代码。这很好用--我的许可证被正确地识别了--但是它有点太“巧合编程”了,让我感觉不舒服。
(我使用的是带有ASP.NET 3.5的C#,如果有什么不同的话。)
发布于 2010-03-10 19:07:21
如果您阅读product documentation,您将看到下面这一行:
在对文档执行任何操作之前,您需要设置许可证。对于每个应用程序(或进程),只需设置一次license 。
因此它是以流程为中心的。
发布于 2012-12-04 18:46:59
在Java版本的Aspose中,您可以通过调用
License.isLicenseSet();它返回一个布尔值。请注意,这是一个静态方法。
发布于 2014-06-17 09:17:00
我尝试创建一个Spring bean来执行此操作(如下所示),但它不起作用。Spring似乎想要调用License.setLicense(Reader)而不是License.setLicense(String)。我得到的错误是无法将类型为'java.lang.String‘的属性值转换为属性’license‘许可证所需的类型'java.io.Reader’。
<bean id="asposeLicense" class="com.aspose.cells.License">
<property name="license" value="Aspose.Cells.lic" />
</bean>然而,我得到了这个更通用的(Java)解决方案:
web.xml:
<!-- does things needing doing when application starts or stops -->
<listener>
<listener-class>
com.xyz.listener.ApplicationStartupListener
</listener-class>
</listener>ApplicationStartupListener.java (新类):
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) {
}
}https://stackoverflow.com/questions/2416216
复制相似问题