我们如何在Web应用程序中注册关闭挂钩?
有没有什么可以在web.xml或applicationContext.xml中注册它?
我知道如果我们使用主类的应用程序,那很简单.
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
context.registerShutdownHook();
Run Code Online (Sandbox Code Playgroud)
但是Web应用程序怎么样?因为它使用ContextListener
如果您遇到需要编辑.mht文件的情况(例如:向网站添加一些文本).
你能否建议编辑.mht(网络档案)文件的最佳方式?
我尝试过的:
(编辑:记事本,单词);
I-Explorer加载项(如HTML快速编辑栏)
在将我的应用程序转换为Web应用程序之前 Log4j将日志记录在我在log4j2.xml中定义的正确日志文件(info.log和debug.log)中.
但是当我将我的应用程序更改为web.app时,所有日志现在都记录到servlet容器(tomcat 7)中的catalina.out文件中.部署应用程序后,log4j2会创建这些日志文件,但它们仍为空,所有日志都会转到catalina.out文件.
你能说出我做错了吗?
在web.xml中,我添加了必要的配置.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>project-service</display-name>
<!-- Support for Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" strict="true" name="XMLConfigTest"
packages="">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<RollingRandomAccessFile name="RollingRandomAccessFileDebug" fileName="/local/deploy/logs/debug.log"
filePattern="logs/$${date:yyyy-MM}/project-%d{MM-dd-yyyy}-%i.log.gz"
immediateFlush="false"
append="false">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] …
Run Code Online (Sandbox Code Playgroud) 在添加context-param和Log4jConfigListener之前Log4j2
,我在catalina.out文件中列出了所有日志.
所以现在,我正在尝试配置log4j
我的Web应用程序.
在web.xml
,我添加了必要的配置.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>etl-service</display-name>
<!-- Support for Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>myprofile</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>/WEB-INF/classes/log4j2.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" strict="true" name="XMLConfigTest"
packages="">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<RollingRandomAccessFile name="RollingRandomAccessFileDebug" fileName="/local/deploy/logs/debug.log"
filePattern="logs/$${date:yyyy-MM}/etl-%d{MM-dd-yyyy}-%i.log.gz"
immediateFlush="false"
append="false">
<PatternLayout>
<Pattern>%d …
Run Code Online (Sandbox Code Playgroud) 我在谷歌找不到.
在Java中用C#中的"{}"打印的可能性是否相同?
C#:
namespace Start
{
public class Program
{
public static void Main(string[] args)
{
string a = "Hi";
Console.WriteLine("{0}", a);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Java:???