我正在尝试在META-INF下的jboss_ejb3.xml中设置JNDI env-entries logback / context-name和app_name。但是当我部署我的ear文件时,log back无法读取JNDI env条目。 / p>
* 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文件时,log back会抛出以下异常
[服务器:服务器二] [0m [0m02:07:20,352 INFO [stdout](MSC服务) 线程1-11)02:07:20,352 | -ERROR in ch.qos.logback.classic.joran.action.InsertFromJNDIAction - [java:comp / env / app_name]具有null或空值_ [0m [服务器:服务器二] [0m [0m02:07:20,353 INFO [stdout](MSC服务) 线程1-11)02:07:20,352 | -ERROR in ch.qos.logback.classic.joran.action.InsertFromJNDIAction - [java:comp / env / app_name]具有null或空值_ [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>
任何建议都将不胜感激! 提前谢谢。
答案 0 :(得分:0)
启动JBOSS服务器时,传递-Dlogback.ContextSelector = JNDI vm args。