I have a servlet that I would like to run within ColdFusion MX 7. I would like to make use of an existing ColdFusion DSN as a javax.sql.DataSource, if possible.
我有一个我想在ColdFusion MX 7中运行的servlet。如果可能的话,我想将现有的ColdFusion DSN用作javax.sql.DataSource。
I thought something like
我觉得有点像
coldfusion.server.ServiceFactory.getDataSourceService().getDatasource(dsname);
would work, but unfortunately the servlet returns
会工作,但不幸的是servlet返回
java.lang.NoClassDefFoundError: coldfusion/server/ServiceFactory
2 个解决方案
#1
1
That code will work fine, you just don't have ServiceFactory in your classpath. Ie, Java can't load that class. Try including a dependency on cfusion.jar from C:\CFusionMX7\lib.
该代码将正常工作,您只是在类路径中没有ServiceFactory。即,Java无法加载该类。尝试在C:\ CFusionMX7 \ lib中包含对cfusion.jar的依赖。
#2
0
It seems the simplest way to do this is to add an additional JNDI datasource into jrun-resources.xml. This can then be accessed in the conventional way:
似乎最简单的方法是在jrun-resources.xml中添加一个额外的JNDI数据源。然后可以以传统方式访问它:
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("mydatasource");
It does mean duplicating database connection configuration, but I would rather do this than work with the largely undocumented coldfusion.server.* classes.
它确实意味着重复数据库连接配置,但我宁愿这样做而不是使用大量未记录的coldfusion.server。*类。
#1
1
That code will work fine, you just don't have ServiceFactory in your classpath. Ie, Java can't load that class. Try including a dependency on cfusion.jar from C:\CFusionMX7\lib.
该代码将正常工作,您只是在类路径中没有ServiceFactory。即,Java无法加载该类。尝试在C:\ CFusionMX7 \ lib中包含对cfusion.jar的依赖。
#2
0
It seems the simplest way to do this is to add an additional JNDI datasource into jrun-resources.xml. This can then be accessed in the conventional way:
似乎最简单的方法是在jrun-resources.xml中添加一个额外的JNDI数据源。然后可以以传统方式访问它:
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("mydatasource");
It does mean duplicating database connection configuration, but I would rather do this than work with the largely undocumented coldfusion.server.* classes.
它确实意味着重复数据库连接配置,但我宁愿这样做而不是使用大量未记录的coldfusion.server。*类。