Logging after exception on application start - spring-boot

Using Spring boot 2.0.5. On application start occurs a exception with is logged 'ConfigServletWebServerApplicationContext : Exception encountered during context initialization'. But i need stacktrace. I was expecting stack trace will be logged later in SpringApplication.reportFailure '"Application run failed"'. But spring boot calls before this method ServletWebServerApplicationContext.stopAndReleaseWebServer and its seems that after this call any logging does not work anymore.

this can be related to your issue: spring boot discussion
spring boot github issue
You can also debug SpringApplication#reportFailure in the end (after catch (throwable)) it has generic logging of any error:
logger.error("Application run failed", ex)
In my case I had the logger from commons-logging which prevented logging to happen.

Related

Spring boot common logging

I'm very new to the spring boot..
I understood that Spring Boot uses Commons Logging for all internal logging.
logging.level.root=warn
logging.level.org.springframework.web=debug
logging.level.org.hibernate=error
after adding this into application.properties file, application logs all the output and exceptions in the console..
so I have a requirement to print the logs only when the system throws the error not for the success response..
so I have a requirement to print the logs only when the system throws the error not for the success response..
The implementation of this requirement IMO heavily depends on your system
From the word "response" I understand that you're working with some kind of controller (like in spring mvc). But the controller method is only an entry point to your backend.
What if the controller calls the service that logs something (message logA), then (after logging) it calls another service that again logs something (message logB) and then in turn calls, dao to call the datatbase?
If, say, DB threw an error, the logA and logB messages are already logged and you can't "take that back".
So, in general, you can log that there was an error by explicitly catching the exception in controller and logging the error, or using Controller advice to intercept and log the exceptions "globally".
When you reach the point where you log the message you can log it with severity, say, ERROR and the logging framework will log it as long as its configured to log messages of that level from that logger.

Google Cloud Platform Log Viewer logs truncate jsonPayload message for error log

The logs I'm viewing in the Log Viewer are truncating the "message" part of the payload, but the "exception" part of the payload doesn't have a limit and shows the entire stacktrace. These logs are for exceptions caught in my service running in Google Cloud.
The service is built with Spring Boot using SLF4J as a logger factory. I use SLF4J's LoggerFactory to create a logger based on the class where it's invoked and when an exception is caught, I log using the logger's error("Exception thrown processing this message: ${message.data}", exception) where message is of type com.google.pubsub.v1.PubsubMessage and exception is a Throwable of type java.lang.Exception.
I had the same problem.
The only way is to jump to Logs Explore and watch the log.

Exception "Unable to commit: transaction marked for rollback" when using camel-jpa and JTA Transactions

I am currently working on a Tutorial to show camel-jpa on Karaf together with JTA Transactions. I use the following route:
from("jpa://net.lr.tutorial.karaf.camel.jpa2jms.model.Person").id("jpa2jms")
.transacted()
.marshal(df)
.bean(new ExceptionDecider())
.to("jms:person");
So I checked if the transactions work by throwing an exception in ExceptionDecider. When I do this I get the following Exception:
https://gist.github.com/3150591
Any ideas what I do wrong? I suspect it might be the way I setup the transaction manager.
You can find my whole project on github:
https://github.com/cschneider/Karaf-Tutorial/tree/master/cameljpa/jpa2jms
This happens when the transaction is marked inside an exception handler but the exception is swallowed. Normally such exceptions should bubble up and cause the whole transaction to rollback.
If the exception is swallowed instead then camel tries to commit at the end which results in the above exception.

Spring does not abort bootstrapping on bean initialization Error when component scanning is enabled?

I have a web application with a spring configuration file. I have the following entry:
<bean id="flyway" class="xxx.FlywayTool" init-method="migrateOrFail"/>
The "flyway" bean is used to initialize and migrate the database.Now I have another bean defining the datasource the application should use:
<bean id="dataSource" class="..." depends-on="flyway">
this one depends on flyway to succeed.
Everything is working fine. Now, when the "flyway" bean throws an exception the bootstrapping of spring stops and the webapp startup is finished - all good.
Now i am starting to enable autowiring for certain components via:
<context:component-scan base-package="de.xxxxx.xxxxx" />
in some of the classes I depend on services which are also defined as beans in the xml configuration. and they I turn depend on the datasource mentioned above.
now the problem: as soon as I bootstrap the application now and "flyway" is throwing an exception the exception is swallowed by spring in the following section:
org.springframework.beans.factory.support.AbstractBeanFactory.getTypeForFactoryBean(String, RootBeanDefinition)
catch (BeanCreationException ex) {
// Can only happen when getting a FactoryBean.
if (logger.isDebugEnabled()) {
logger.debug("Ignoring bean creation exception on FactoryBean type check: " + ex);
}
onSuppressedException(ex);
return null;
}
and now spring tries, for every other dependend service (that depends on the datasource and therefore flyway) initialize all the beans which in turn results in the same procedure again and again.
This exceptional loop continues until spring is finished trying to instaniate every possible dependency instead of aborting after the first flyway error.
This strange behaviour only starts when I enable component scanning via
<context:component-scan ....
when this feature is disabled spring stops after the first flyway error happend. It also ends up in another class:
org.springframework.context.support.AbstractApplicationContext.refresh()
catch (BeansException ex) {
// Destroy already created singletons to avoid dangling resources.
destroyBeans();
// Reset 'active' flag.
cancelRefresh(ex);
// Propagate exception to caller.
throw ex;
}
so this is the behaviour i would expect in the other case too.
our spring version: 3.0.6.RELEASE
this behaviour is also present with other classes throwing any runtime execption (not just flyway) is this a bug or expected behaviour?
any help highly appreciated
marcel
Put <context:component-scan... after your beans declaration in your XML file as nico_ekito said in comments.
Confirmed to work:
Marcel: wow, that seems to work. you reckon i should open a bug? or is this intended behaviour?

SRVE0014E: uncaught service exception

I am getting below exception on one of our development environment. But it is working fine on another environment. unable to catch the trick. Can somebody help on this.
SRVE0014E: Uncaught service() exception root cause Jersey Spring Web
Application: `javax.servlet.ServletException: java.io.EOFException:
No content to map to Object due to end of input `
SRVE0014E appears to be application error. I would recommend checking the application log during the time of the exception thrown from the WebSphere exception. Additionally, investigate the functionality and behavior of Jersey Spring Web Application.

Resources