我正在使用 Quartz 和 Spring 技术的调度程序。
是否可以在不创建主类的情况下启动我的上下文?不使用以下示例:
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main( String[] args ) throws Exception
{
new ClassPathXmlApplicationContext("Spring-Quartz.xml");
}
}
例如,我希望在启动 jetty 服务器时配置我的上下文。
最佳答案
如果您在应用程序服务器上启动您的 spring 应用程序,您可以在 web.xml 中使用一个监听器来启动您的 spring 容器。
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:context.xml</param-value>
</context-param>
另一个例子: 如果您想在蓝图 OSGi 环境中使用 spring,蓝图扩展程序会为您启动 META-INF/spring 或 OSGI-INF/blueprint 中的所有上下文。
关于java - 在没有主类的情况下启动应用程序上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22247845/