This is how I solved the problem - I get the DataSource inside the appender start method via JNDI, and then create my JDBCTemplate. It worked great for me - no problem.
public class MyAppender extends AppenderBase<ILoggingEvent> { private String _jndiLocation; private JDBCTemplate _jt; public void setJndiLocation(String jndiLocation) { _jndiLocation = jndiLocation; } @Override public void start() { super.start(); if (_jndiLocation == null) { throw new IllegalStateException("Must have the JNDI location"); } DataSource ds; Context ctx; try { ctx = new InitialContext(); Object obj = ctx.lookup(_jndiLocation); ds= (DataSource) obj; if (ds == null) { throw new IllegalStateException("Failed to obtain data source"); } _jt = new JDBCTemplate(ds); } catch (Exception ex) { throw new IllegalStateException("Unable to obtain data source", ex); } } @Override protected void append(ILoggingEvent e) {
I donβt know if you are facing the same problem, but I had to use a multi-step configuration (as described here ) because I received the SLF4J error message "log-log substitue logger" ( described here ).
source share