我正在尝试在 META-INF 下的 jboss_ejb3.xml 中设置 JNDI env-entries logback/context-name 和 app_name。但是当我部署我的 ear 文件日志时,无法读取 JNDI env 条目。
* jboss-ejb3.xml 文件: *
<?xml version="1.1" encoding="UTF-8"?>
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="urn:clustering:1.0"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1"
impl-version="2.0">
<enterprise-beans>
<session>
<ejb-name>TestLogBean</ejb-name>
<env-entry>
<description>JNDI logging context for this app</description>
<env-entry-name>logback/context-name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>yoda</env-entry-value>
</env-entry>
<env-entry>
<description>Application name</description>
<env-entry-name>app_name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>SampleLogger</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
</jboss:ejb-jar>
当我部署 ear 文件时,返回日志会引发以下异常
[Server:server-two] [0m [0m02:07:20,352 INFO [stdout](MSC 服务线程 1-11)02:07:20,352 |-ch.qos.logback.classic.joran.action.InsertFromJNDIAction 中的错误 - [java:comp/env/app_name] 具有空值或空值_[0m [Server:server-two] [0m [0m02:07:20,353 INFO [stdout] (MSC 服务线程 1-11) 02:07:20,352 |- ch.qos.logback.classic.joran.action.InsertFromJNDIAction 中的错误 - [java:comp/env/app_name] 具有空值或空值_[0m
logback.xml 文件:
<configuration debug="true">
<insertFromJNDI env-entry-name="java:comp/env/app_name" as="app_name" />
<property name="messagePattern" value="%d [%thread] %-5level ${app_name}.%logger{46} - %msg%n"/>
<appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>JNDI-TEST %d %-5level %msg %logger{50}%n</Pattern>
</layout>
</appender>
<root level="DEBUG">
<appender-ref ref="CON" />
</root>
</configuration>
任何建议将不胜感激!提前致谢。