说明:
在应用服务器(tomcat,jboss,weblogic)启动的时候,启动HSQL数据库。
步骤:
1。在web.xml下配置监听器
xml 代码
- <listener>
- <listener-class>
- com.emap.mds.db.RunHSQLListener
- listener-class>
- listener>
注意:这个监听器必须配置在spring和其他监听器的前面(在web.xml的顺序)。
2.编写监听器
java 代码
- public class RunHSQLListener implements ServletContextListener
- {
- /**
- * Initialize the root web application context.
- */
- public void contextInitialized( ServletContextEvent event)
- {
- ServletContext context = event.getServletContext();
- context.log("开始启动HSQL数据库..");
- org.hsqldb.Server.main(new String[] { "-database.0",
- context.getRealPath("/WEB-INF/db/mds"), "-dbname.0", "mds" });
- context.log("成功启动HSQL数据库");
- }
- /**
- * Create the ContextLoader to use. Can be overridden in subclasses.
- *
- * @return the new ContextLoader
- */
- protected ContextLoader createContextLoader()
- {
- return new ContextLoader();
- }
- /**
- * Close the root web application context.
- */
- public void contextDestroyed( ServletContextEvent event)
- {
- }
- }
注意:hsql数据库放在WEB-INF的db文件夹下,cms是数据库名称,别名是cms。