当前位置: 首页 > 知识库问答 >
问题:

在Spring boot中没有加载logback JNDI选择器

姬天宇
2023-03-14
<env-entry>
    <env-entry-name>logback/context-name</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>appA</env-entry-value>
</env-entry>

我想也许我可以使用logging.config强制使用这些logging.config=z://dev/...../logback-app.xml或logging.config=file:z://dev/...../logback-app.xml或logging.config=classepath:logback-app.xml的logback配置文件,它们都不能加载该文件。在org.springframework.boot.logging.logback.LogBackLoggingSystem类的第67行,字符串configLocation为空。

即使设置了logging.config=z://dev/.../logback-spring.xml,也无法加载il。

我想我不能使用spring活动配置文件,因为appB不使用Spring Boot。

共有1个答案

阴培
2023-03-14

我也遇到了同样的问题,经过几天的搜索,这个链接证明是最有帮助的:http://rostislav-matl.blogspot.com/2013/03/remensed-logback-config-file-for-web.html

在spring初始值设定项中,您可以重写onStartup,以添加自定义侦听器:

  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    // Add the customer listener to configure logback
    servletContext.addListener(CustomServletContextListener.class);
    super.onStartup(servletContext);
  }
public class CustomServletContextListener implements ServletContextListener {

  @Override
  public void contextInitialized(ServletContextEvent contextEvent) {
    // Get the war/context name from this context event
    String contextName = contextEvent.getServletContext().getContextPath().substring(1);

    // Get the path of the logback configuration file
    URL configFileURL = Thread.currentThread().getContextClassLoader().getResource("logback-" + contextName + ".xml");

    // If the URL exists in the classpath
    if (configFileURL != null) {
      try {
        // Reset the existing logger context and set the name to match the current context
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        loggerContext.reset();
        loggerContext.setName(contextName);

        // Update the logger context and configure the logger based on the configuration file
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(loggerContext);
        configurator.doConfigure(configFileURL);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
}
 类似资料:
  • 控制台报这样的错 .yml文件我是这样配置 证书名中.cloud是我的域名后缀 pom文件有添加这个插件的依赖 /cert/.pfx 和 cert/.pfx都试过了,还是找不到

  • 问题内容: 我想在下面的HTML片段中选择BONKERS。它的区别在于,它是单独存在的,而其所有兄弟姐妹都包含。是显而易见的选择,但由于文本节点而无法使用。我以为我知道这些东西,但这正驱使我疯狂。 我需要一个纯CSS解决方案(不能选择JS),并且无法控制源HTML。 ! 问题答案: 您可以按照这种方法。通过所需的CSS 设置元素的样式,然后重置可在样式中继承的CSS样式,即: CSS: 您可能不需

  • 我对log4j相当陌生。正在尝试使用log4j2。要配置的xml。我将该文件添加到构建路径,它工作了一次,但不再工作。 这是我的log4j2.xml: 我把它拆下来,只是为了测试它,让它工作。我检查了调试,并且记录器配置使用默认值。 我还试着给文件命名log4j2-test.xml. 有什么想法吗? 谢啦

  • 问题内容: 我正在尝试加载对象(.obj)文件以与three.js一起使用并做出反应(使用react-three-renderer),但得到的My代码如下: 但是,我不断得到:“在’三个’中找不到导出’OBJLoader’(导入为’三个’)有人有主意吗? 问题答案: 因此,似乎添加到react组件上就可以了(怪异,是吗?)。所以我的代码目前看起来像:

  • 我在这里找到了部分解决方案如何使用自定义对象在JavaFX中填充ListView?这里的javafx-listview项带有一个图像按钮,但问题仍然存在,我不知道如何以及在哪里放置标记,以便在单击一个项时加载它。

  • 我想更改页面加载时的“选择组件”值。我读了相关的帖子,那里提出的每一个解决方案都适用于点击按钮。然而,我想要的是在页面加载后设置值,而不需要任何用户操作。我拥有的是: 以及: 我有相同的代码附加到按钮上,并且它可以工作。它只是不适用于准备()函数。所以我的问题是:如何在页面加载后设置选择值? 完整html