Spring *-servlet.xml Websphere 服务器启动时未加载
Spring *-servlet.xml not getting Loaded on Websphere Server Startup
我一直在尝试 运行 服务器启动后立即使用一种方法。 (根据我的理解,问题可能是在服务器启动或重新启动时未加载上下文)。 下面这个适用于 Tomcat 感觉 Websphere 正在做一个惰性初始化,它不应该
当我在 Websphere 上部署组件或重新启动它时,上下文不会加载,除非我点击 URL 例如“http://localhost/myapp/”
我已经尝试了 3 种方法 运行 方法
- Scheduling
@EnableScheduling
public class MyClass{
MyClass(){
}
@Scheduled(cron = "2 * * * * *")
public void myMethod() {
}
- Init
<bean id="myClass" class="com.abc.abc.billing.myClass" init-method="readConfigScheduler"/>
- ApplicationListener
@Component
public class StartUp implements ApplicationListener<ContextRefreshedEvent>
{
@Autowired
private MyClass cls;
@Override
public void onApplicationEvent(ContextRefreshedEvent arg0)
{
System.out.println("ContextLoaded");
cls.MyMethod();
}
}
只要我点击URL“http://localhost/myapp/”,以上三种方法都有效。
我已经尝试过以下链接寻求帮助,但我无法使其正常工作。
Execute method on startup in spring
我还与少数人交谈过,他们在尝试时说它可以工作,但在后来的调查中我发现当你通过 eclipse 部署应用程序时,它会自动打开应用程序的 url 加载上下文。
所以当我们重新启动应用程序时它没有工作
My Web.xml looks something like this
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>MyApp</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/MyApp-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
我对 Spring 很陌生,所以任何帮助都会很好
org.springframework.web.context.ContextLoaderListener
您可能想要创建自己的 ServletContextListener,它应该扩展到 ContextLoaderListener
以上。我就是这样做的。确保在您要实现的 contextInitialized
方法中调用 super.contextInitialized(...)
,并且您必须在 xml.[=15= 中用您的 class 名称替换上面的标签]
例如 -
<listener>
<listener-class>a.b.c.e.f.MyContextLoaderListener</listener-class>
</listener>
您似乎遇到了与此
中描述的相同的问题
默认情况下,websphere 通过在收到对 web 应用程序的请求之前不启动 servlet 来优化服务器启动时间和内存使用,如果要在安装 web 应用程序时加载 servlet,请将以下行添加到server.xml
配置文件或其包含的文件:
<webContainer deferServletLoad="false"/>
我一直在尝试 运行 服务器启动后立即使用一种方法。 (根据我的理解,问题可能是在服务器启动或重新启动时未加载上下文)。 下面这个适用于 Tomcat 感觉 Websphere 正在做一个惰性初始化,它不应该
当我在 Websphere 上部署组件或重新启动它时,上下文不会加载,除非我点击 URL 例如“http://localhost/myapp/”
我已经尝试了 3 种方法 运行 方法
- Scheduling
@EnableScheduling
public class MyClass{
MyClass(){
}
@Scheduled(cron = "2 * * * * *")
public void myMethod() {
}
- Init
<bean id="myClass" class="com.abc.abc.billing.myClass" init-method="readConfigScheduler"/>
- ApplicationListener
@Component
public class StartUp implements ApplicationListener<ContextRefreshedEvent>
{
@Autowired
private MyClass cls;
@Override
public void onApplicationEvent(ContextRefreshedEvent arg0)
{
System.out.println("ContextLoaded");
cls.MyMethod();
}
}
只要我点击URL“http://localhost/myapp/”,以上三种方法都有效。
我已经尝试过以下链接寻求帮助,但我无法使其正常工作。
Execute method on startup in spring
我还与少数人交谈过,他们在尝试时说它可以工作,但在后来的调查中我发现当你通过 eclipse 部署应用程序时,它会自动打开应用程序的 url 加载上下文。
所以当我们重新启动应用程序时它没有工作
My Web.xml looks something like this
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>MyApp</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/MyApp-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
我对 Spring 很陌生,所以任何帮助都会很好
org.springframework.web.context.ContextLoaderListener
您可能想要创建自己的 ServletContextListener,它应该扩展到 ContextLoaderListener
以上。我就是这样做的。确保在您要实现的 contextInitialized
方法中调用 super.contextInitialized(...)
,并且您必须在 xml.[=15= 中用您的 class 名称替换上面的标签]
例如 -
<listener>
<listener-class>a.b.c.e.f.MyContextLoaderListener</listener-class>
</listener>
您似乎遇到了与此
默认情况下,websphere 通过在收到对 web 应用程序的请求之前不启动 servlet 来优化服务器启动时间和内存使用,如果要在安装 web 应用程序时加载 servlet,请将以下行添加到server.xml
配置文件或其包含的文件:
<webContainer deferServletLoad="false"/>