log4j JDBC appender SQL executed at Spring boot startup

你说的曾经没有我的故事 提交于 2020-02-06 19:00:04

问题


I am trying to follow the same structure as defined at below link and I get SQLexception while starting up the spring boot Application.

log4j2 patternlayout for columnmapping not working

log4j.xml:

<JDBC name="DBLogger" tableName="mytable" ignoreExceptions="true">
        <DriverManager
            connectionString="jdbc:oracle:thin:@host:port/service" userName="XXXXXX"
            password="XXXX" driverClassName="oracle.jdbc.driver.OracleDriver" />

        <ColumnMapping name="CREATED_DTTM"  isEventTimestamp="true"/>
        <ColumnMapping name="APPL_NAME" />          <ColumnMapping name="MESSAGE_NAME" />
        <ColumnMapping name="OPERATION" />
        <ColumnMapping name="PROCESS_SERVER_NAME" />
        <ColumnMapping name="RESPONSE_RESULT" />
        <ColumnMapping name="TABLE_PRIMARY_ID"/>
        <ColumnMapping name="SESSION_ID" />
        <ColumnMapping name="UUID" />
        <MessageLayout />
</JDBC>


 <Loggers>

    <Logger name="com.mycompany.package.controller"
        level="trace" additivity="false">
        <AppenderRef ref="DBLogger"/>
    </Logger>
    <Root level="trace">
        <AppenderRef ref="DBLogger" />
    </Root>
</Loggers>

MyController.Java

Logger dbLogger = LogManager.getLogger(MyController.class);
   final MapMessage mapMessage = new MapMessage();
      mapMessage.with("CREATED_DTTM", new Date());
      mapMessage.with("APPL_NAME", "MYAPP");
      mapMessage.with("MESSAGE_NAME", "MY_REQUEST");
      mapMessage.with("OPERATION", "myOperation");
      mapMessage.with("PROCESS_SERVER_NAME", "LOCAL");
      mapMessage.with("RESPONSE_RESULT", "SUCCESS");
      mapMessage.with("SERVICE_TYPE_ID", 4);
      mapMessage.with("TABLE_PRIMARY_ID", 456789);
      mapMessage.with("SESSION_ID", "123456789");
      mapMessage.with("UUID", "abcd34567tyrtgg45435revf");
      dbLogger.trace((mapMessage));

Code has been compiled fine and when start the application as spring boot. I see application failed and could not start.

Error Message:

2019-08-23 10:45:58,037 main ERROR Unable to write to database [JdbcManager{name=DBLogger, bufferSize=0, tableName=mytable, columnConfigs=[], columnMappings=[ColumnMapping [name=CREATED_DTTM, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=APPL_NAME, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=MESSAGE_NAME, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=OPERATION, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=PROCESS_SERVER_NAME, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=RESPONSE_RESULT, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=TABLE_PRIMARY_ID, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=SERVICE_TYPE_ID, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=SESSION_ID, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null], ColumnMapping [name=UUID, source=null, literalValue=null, parameter=null, type=class java.lang.String, layout=null]]}] for appender [DBLogger]. org.apache.logging.log4j.core.appender.db.DbAppenderLoggingException: Failed to insert record for log event in JDBC manager: Missing IN or OUT parameter at index:: 1
at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:798)
at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeThrough(JdbcDatabaseManager.java:823)
at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:264)
at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:110)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2170)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2125)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2108)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1985)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1843)
at org.apache.commons.logging.LogAdapter$Log4jLog.log(LogAdapter.java:265)
at org.apache.commons.logging.LogAdapter$Log4jLog.trace(LogAdapter.java:250)
at org.springframework.boot.logging.DeferredLog.logTo(DeferredLog.java:221)
at org.springframework.boot.logging.DeferredLog.replayTo(DeferredLog.java:187)
at org.springframework.boot.logging.DeferredLog.switchTo(DeferredLog.java:167)
at org.springframework.boot.logging.DeferredLog.switchTo(DeferredLog.java:157)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationPreparedEvent(ConfigFileApplicationListener.java:196)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:93)
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:66)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:393)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.mycompany.package..MyApplication.main(MyApplication.java:67)Caused by: java.sql.SQLException: Missing IN or OUT parameter at index:: 1
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2086)
at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:9713)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.addBatch(OraclePreparedStatementWrapper.java:1067)
at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:792)
... 37 more

Why SQL is being executed at the server start up? My controller should get called when the request comes in( no request comes at start up).

Any help will be appreciated.

来源:https://stackoverflow.com/questions/57629701/log4j-jdbc-appender-sql-executed-at-spring-boot-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!