I use gradle as build tool for a spring boot application and there I am confronted with some strange behavior. Gradle shows more logging-information on explicitly turn test-outputs off as if I do not specify anything at all.
This is quite strange, because a explicit disable-statement should be at least as expressive as no configuration, or shouldn't it?
Example:
If I add the following lines to my build.gradle, I get a by far more verbose logging output on running gradle test:
test{
testLogging {
showStackTraces = false
showStandardStreams = false
showExceptions = false
showCauses = false
events "failed"
exceptionFormat "short"
}
}
EDIT:
I changed it to events = [] as #Peter_Niederwieser suggested. Now nearly all messages disappear, except the following one. Has somebody or other an idea how I can suppress them all? I only want to show the result 34 tests completedand maybe a link to the report.
:backend:test
Download http://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.pom
Download http://repo1.maven.org/maven2/org/jacoco/org.jacoco.build/0.6.2.201302030002/org.jacoco.build-0.6.2.201302030002.pom
Download http://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.jar
objc[1360]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
08:50:37.135 [Thread-7] INFO o.s.c.s.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext#228186d4: startup date [Sat Dec 06 08:50:35 CET 2014]; root of context hierarchy
08:50:37.135 [Thread-6] INFO o.s.c.s.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext#4d18a206: startup date [Sat Dec 06 08:50:35 CET 2014]; root of context hierarchy
08:50:37.135 [Thread-5] INFO o.s.c.s.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext#5221dfe5: startup date [Sat Dec 06 08:50:35 CET 2014]; root of context hierarchy
08:50:37.135 [Thread-8] INFO o.s.w.c.s.GenericWebApplicationContext - Closing org.springframework.web.context.support.GenericWebApplicationContext#5a5fbef7: startup date [Sat Dec 06 08:50:36 CET 2014]; root of context hierarchy
08:50:37.166 [Thread-7] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.166 [Thread-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.167 [Thread-5] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.167 [Thread-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.167 [Thread-7] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#65bad9fe: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.168 [Thread-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#c355f75: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.168 [Thread-5] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#6dd79791: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.168 [Thread-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#75a5ec9: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.co ntext.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.175 [Thread-7] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'
08:50:37.175 [Thread-6] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'
08:50:37.176 [Thread-5] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'
08:50:37.176 [Thread-8] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'
34 tests completed, 9 failed
:backend:test FAILED
The default is events = []. The code above sets events "failed", which will result in more verbose logging (each failed test will be logged individually).
Related
We have written a basic streams processor using Spring Cloud Stream (3.0.9.RELEASE) and the Kafka streams binder. The actual project contains multiple classes annotated with #SpringBootApplication, each with their own functions, but only one is used at a time.
The issue we're having is that, when bundling our app into a JAR and running it as a k8s deployment, if we run any more than 1 replica at a time, those additional replicas terminate after a few minutes with no meaningful error message or obvious reason why. For example, if we run 5 replicas, 1 will stay up indefinitely and process events, but the other 4 (although they too initially start to process events) will exit shortly after. Obviously if we set our deployment to run only 1 replica there is no issue, but the processor needs to be scalable.
This section of the documentation regarding setting an application ID seems relevant:
For production deployments, it is highly recommended to explicitly specify the application ID
through configuration. This is especially going to be very critical if you are auto scaling your
application in which case you need to make sure that you are deploying each instance with the
same application ID.
but neither setting this value at the binding level (for our normalize function):
spring:
cloud:
stream:
kafka:
streams:
binder:
functions:
normalize:
applicationId: normalizer-full
nor setting it at the binder level:
spring:
cloud:
stream:
kafka:
streams:
binder:
applicationId: normalizer-full
seems to be able to keep the subsequent pods running.
Any help appreciated.
-- EDIT --
Here is a capture of the trace logging When the processor shuts down after several minutes:
2020-11-20 06:32:09.721 DEBUG 1 --- [extShutdownHook] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#34f7cfd9, started on Fri Nov 20 06:26:59 GMT 2020
2020-11-20 06:32:09.722 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'org.springframework.integration.config.IdGeneratorConfigurer#0'
2020-11-20 06:32:09.722 DEBUG 1 --- [extShutdownHook] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#5e1dde44, started on Fri Nov 20 06:27:23 GMT 2020, parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#34f7cfd9
2020-11-20 06:32:09.722 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'lifecycleProcessor'
2020-11-20 06:32:09.723 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#38830ea: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,KStreamBinderConfiguration,org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory,org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration,org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor,org.springframework.boot.context.internalConfigurationPropertiesBinderFactory,org.springframework.boot.context.internalConfigurationPropertiesBinder,org.springframework.boot.context.properties.BoundConfigurationProperties,org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,org.springframework.cloud.stream.binder.kafka.streams.MultiBinderPropertiesConfiguration,provisioningProvider,kStreamBinder]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#7cb502c
2020-11-20 06:32:09.723 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Retrieved dependent beans for bean 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory': [org.springframework.context.annotation.internalConfigurationAnnotationProcessor]
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'lifecycleProcessor'
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'outputBindingLifecycle'
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'inputBindingLifecycle'
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'streamsBuilderFactoryManager'
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean '_org.springframework.integration.errorLogger'
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'integrationHeaderChannelRegistry'
2020-11-20 06:32:09.724 TRACE 1 --- [extShutdownHook] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'stream-builder-normalize'
2020-11-20 06:32:09.724 DEBUG 1 --- [extShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483547
...
package com.basicspring.basicapp;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class Config {
#Bean
public Dependency dependency(){
System.out.println("In dependency");
return new Dependency();
}
#Bean
public DependencyContainer dependencyContainer(){
System.out.println("In dependencyContainer");
dependency();
dependency();
dependency();
return new DependencyContainer(dependency());
}
}
Output:
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify: none and -no verify were deprecated in JDK 13 and will likely be removed in a future release.
22:00:36.567 [main] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#7276c8cd
22:00:36.601 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
22:00:36.759 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor'
22:00:36.762 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
22:00:36.765 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
22:00:36.766 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
22:00:36.778 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'config'
22:00:36.798 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'dependency'
In dependency
22:00:36.820 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'dependencyContainer'
In dependencyContainer
22:00:36.833 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties' with value of type String
Process finished with exit code 0
Please look at the statements "In dependency" and "In dependencyContainer" in the output. Even after manually calling the dependency() method twice in dependencyContainer() method, it's not getting executed twice.
Default scope of a spring bean is singleton. Meaning there is only a single instance of a bean that is used throughout the application. If you use the #Configuration, calls to methods annotated with #Bean get routed to check if there is already an instance of the bean. If an instance is present that instance is returned without executing the function. If you remove the #Configuration annotation all the three calls get executed.
I already add #SpringBootTest in all testcase.
'Run all test' in IDEA is OK, but when I use Maven test it didn't work.
how to reuse context in Maven test commend.
has any friend meet this problem? thx!
my test case like this:
#SpringBootTest
class EventControllerTest extends BaseTester{
...
}
#RunWith(SpringRunner::class)
#SpringBootTest
class BaseTester{}
maven log:
2018-07-04 16:09:38.766 INFO [-,,,] 12601 --- [ Thread-9] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext#2577d6c8: startup date [Wed Jul 04 16:09:29 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#54eb2b70
2018-07-04 16:09:38.792 INFO [-,,,] 12601 --- [ Thread-9] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
Running com.fintend.ctc.controller.InviteControllerTest
16:09:40.535 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.fintend.ctc.controller.InviteControllerTest]
16:09:40.541 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
16:09:40.549 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
16:09:40.570 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test c
I have a Spring reactive sample application that was modified from one of the examples that was provided in the the Spring Webflux documentation. The master branch of this application uses Spring Boot in the traditional manner, with an embedded application server (Netty). It is working fine.
In the Liberty branch, I am trying to build the application as a WAR and deploy to Websphere Liberty Profile. Aside from changes to the build process, the most significant code change is having my Application.java (source here) extend AbstractAnnotationConfigDispatcherHandlerInitializer, as per Webflux documentation:
For Servlet containers especially with WAR deployment you can use the AbstractAnnotationConfigDispatcherHandlerInitializer which as a WebApplicationInitializer and is auto-detected by Servlet containers. It takes care of registering the ServletHttpHandlerAdapter as shown above. You will need to implement one abstract method in order to point to your Spring configuration.
However, when I do this, none of my resources/endpoints get mapped and none of my beans that I declare in Application.java are registered. This is the full output that I get, with the exception being thrown when trying to access the context root:
13:29:48.848 [Default Executor-thread-6] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
13:29:48.855 [Default Executor-thread-6] INFO org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#4ba0f9a4: startup date [Fri Oct 13 13:29:48 CDT 2017]; root of context hierarchy
13:29:48.857 [Default Executor-thread-6] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Bean factory for org.springframework.context.annotation.AnnotationConfigApplicationContext#4ba0f9a4: org.springframework.beans.factory.support.DefaultListableBeanFactory#41daf3ea: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory]; root of factory hierarchy
13:29:48.907 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
13:29:48.907 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
13:29:48.939 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
13:29:48.943 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
13:29:49.371 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
13:29:49.371 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
13:29:49.372 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
13:29:49.425 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
13:29:49.426 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
13:29:49.426 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
13:29:49.428 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
13:29:49.432 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
13:29:49.433 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
13:29:49.433 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
13:29:49.441 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' to allow for resolving potential circular references
13:29:49.450 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
13:29:49.454 [Default Executor-thread-6] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource#5c88ddc5]
13:29:49.458 [Default Executor-thread-6] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster#6a00d295]
13:29:49.461 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#41daf3ea: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory]; root of factory hierarchy
13:29:49.462 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
13:29:49.462 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
13:29:49.462 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
13:29:49.463 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
13:29:49.463 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor'
13:29:49.463 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor'
13:29:49.477 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.event.internalEventListenerProcessor' to allow for resolving potential circular references
13:29:49.479 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor'
13:29:49.480 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
13:29:49.480 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.event.internalEventListenerFactory'
13:29:49.481 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.event.internalEventListenerFactory' to allow for resolving potential circular references
13:29:49.483 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.event.internalEventListenerFactory'
13:29:49.484 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
13:29:49.514 [Default Executor-thread-6] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor#6ffc157d]
13:29:49.515 [Default Executor-thread-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
13:29:49.520 [Default Executor-thread-6] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source
[AUDIT ] CWWKZ0001I: Application spring-reactive-playground started in 3.480 seconds.
[AUDIT ] CWWKF0012I: The server installed the following features: [servlet-3.1, websocket-1.1].
[AUDIT ] CWWKF0011I: The server LibertyProjectServer is ready to run a smarter planet.
13:30:05.943 [Default Executor-thread-14] DEBUG reactor.util.Loggers$LoggerFactory - Using Slf4j logging framework
13:30:05.994 [Default Executor-thread-14] DEBUG org.springframework.web.reactive.DispatcherHandler - Processing GET request for [http://localhost:9080/]
13:30:06.041 [Default Executor-thread-14] ERROR org.springframework.web.server.adapter.HttpWebHandlerAdapter - Failed to handle request
org.springframework.web.server.ResponseStatusException: Response status 404 with reason "No matching handler"
at org.springframework.web.reactive.DispatcherHandler.<clinit>(DispatcherHandler.java:74)
at org.springframework.web.reactive.support.AbstractDispatcherHandlerInitializer.createDispatcherHandler(AbstractDispatcherHandlerInitializer.java:145)
at org.springframework.web.reactive.support.AbstractDispatcherHandlerInitializer.registerDispatcherHandler(AbstractDispatcherHandlerInitializer.java:90)
at org.springframework.web.reactive.support.AbstractDispatcherHandlerInitializer.onStartup(AbstractDispatcherHandlerInitializer.java:63)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at com.ibm.ws.webcontainer.webapp.WebApp.initializeServletContainerInitializers(WebApp.java:2539)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1055)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6595)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:468)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:463)
at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:1120)
at com.ibm.ws.webcontainer.osgi.WebContainer.startModule(WebContainer.java:925)
at com.ibm.ws.app.manager.module.internal.ModuleHandlerBase.deployModule(ModuleHandlerBase.java:100)
at com.ibm.ws.app.manager.module.internal.DeployedModuleInfoImpl.installModule(DeployedModuleInfoImpl.java:50)
at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployModules(DeployedAppInfoBase.java:420)
at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:406)
at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:66)
at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:141)
at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1259)
at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:874)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
I have also tried deploying to Tomcat 9 and I get the same problem. I have previously successfully deployed traditional Spring MVC applications as a WAR by extending SpringBootServletInitializer instead of AbstractAnnotationConfigDispatcherHandlerInitializer. What is the equivalent process for Spring Webflux applications? What am I missing in my project code?
Spring 5 brings some variants of WebApplicationInitializer for webflux based applications.
Before Spring 5.0.2(Spring Boot 2.0.0.M7 aligned with this version), there is a bug in AbstractAnnotationConfigDispatcherHandlerInitializer, and in 5.0.2, this class is marked as #Deprecated, there is a new AbstractReactiveWebInitializer introduced. But this class seems also buggy, I have to override the createApplicationContext() to make it work.
See the comments in my sample AppInitializer for more details.
Check my workable war sample which was tested successfully on tomcat.
Using AbstractReactiveWebInitializer ( see #Hantsy answer) well suits for non-SpringBoot applications, as it creates correspondent context.
To start SpringBoot WebFlux application in servlet container, I use the following way:
Disable auto-configuration for embedded servlet containers:
#EnableWebFlux
#SpringBootApplication
#EnableAutoConfiguration(exclude={ReactiveWebServerFactoryAutoConfiguration.class})
public class MyWebfluxApplication {
//this method actionally will not be executed
//public static void main(String[] args) {
// SpringApplication.run(MyWebfluxApplication.class, args);
//}
}
Create custom WebApplicationInitializer:
public class ReactiveWebInitializer implements WebApplicationInitializer {
private ConfigurableApplicationContext springContext;
#Override
public void onStartup(final ServletContext servletContext) throws ServletException {
servletContext.addListener(this);
SpringApplication app = new SpringApplication(MyWebfluxApplication.class);
app.addInitializers((appCtx)->{
// this initializer stores servlet context in spring context
appCtx
.getBeanFactory()
.registerSingleton("storedServletContext",servletContext);
});
this.springContext = app.run("--debug");
}
public void contextDestroyed(ServletContextEvent sce) {
springContext.stop();
springContext
.getBeansOfType(ExecutorConfigurationSupport.class)
.values()
.forEach(ExecutorConfigurationSupport::destroy);
}
}
Create custom ReactiveWebServerFactory as bean :
#Component
public class ServletContextReactiveWebServerFactory implements ReactiveWebServerFactory {
#Autowired
private ServletContext storedServletContext;
private static final String DEFAULT_SERVLET_NAME = "http-handler-adapter";
#Override
public WebServer getWebServer(HttpHandler httpHandler) {
// create and register special servlet
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
ServletRegistration.Dynamic registration = storedServletContext.addServlet(DEFAULT_SERVLET_NAME, servlet);
if (registration == null) {
throw new IllegalStateException("Failed to register servlet with name '" + DEFAULT_SERVLET_NAME + "'. " +
"Check if there is another servlet registered under the same name.");
}
registration.setLoadOnStartup(1);
registration.addMapping("/");
registration.setAsyncSupported(true);
//we cannot control external server/tomcat, so the webserver does nothing
return new WebServer(){
public void start() throws WebServerException {}
public void stop() throws WebServerException {}
public int getPort() {
return 8080;
}
};
}
}
Now, you may package you SpringBoot WebFlux application as war and launch in servlet container.
I took #Eugene answer and added some changes:
#SpringBootApplication //No need to exclude some autoconfiguration classes
public class TestReactProjectApplication implements WebApplicationInitializer {
//This application will start from tomcat and IDE
public static void main(String[] args) {
SpringApplication.run(TestReactProjectApplication.class, args);
}
#Override
public void onStartup(ServletContext ctx) throws ServletException {
SpringApplication app = new
SpringApplication(TestReactProjectApplication.class);
app.addInitializers((appCtx)->{
// this initializer stores servlet context in spring context
appCtx
.getBeanFactory()
.registerSingleton("storedServletContext",ctx);
appCtx
.getBeanFactory()
.registerSingleton("reactiveWebServerFactory",new
MyReactiveWebServerFactory(ctx)); //ReactiveWebServerFactoryAutoConfiguration will not autoconfigure if class ReactiveWebServerFactory exists
});
app.run("--debug");
}
}
And for ReactiveWebServerFactory i extend an existing EmbededTomcatFactory (i think it easier than create own implementation):
public class MyReactiveWebServerFactory extends TomcatReactiveWebServerFactory {
private ServletContext storedServletContext;
private static final String DEFAULT_SERVLET_NAME = "http-handler-adapter";
public MyReactiveWebServerFactory(ServletContext storedServletContext) {
this.storedServletContext = storedServletContext;
}
#Override
public WebServer getWebServer(HttpHandler httpHandler) {
// create and register special servlet
ServletHttpHandlerAdapter servlet = new
ServletHttpHandlerAdapter(httpHandler);
ServletRegistration.Dynamic registration =
storedServletContext.addServlet(DEFAULT_SERVLET_NAME, servlet);
if (registration == null) {
throw new IllegalStateException("Failed to register servlet with name '" + DEFAULT_SERVLET_NAME + "'. " +
"Check if there is another servlet registered under the same name.");
}
registration.setLoadOnStartup(1);
registration.addMapping("/");
registration.setAsyncSupported(true);
//we cannot control external server/tomcat, so the webserver does nothing
return new WebServer(){
public void start() throws WebServerException {}
public void stop() throws WebServerException {}
public int getPort() {
return 8080;
}
};
}
}
Here's my log message.
09:24:21.633 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy#0'
09:24:21.633 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean '(inner bean)#32311ede'
09:24:21.637 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean '(inner bean)#32311ede'
09:24:21.637 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authentication.ProviderManager#0'
09:24:21.638 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authentication.ProviderManager#0'
09:24:21.638 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'
09:24:21.638 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'
09:24:21.640 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0' to allow for resolving potential circular references
09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'
09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.security.authentication.AnonymousAuthenticationProvider#0'
09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
09:24:21.643 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
09:24:21.644 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' to allow for resolving potential circular references
09:24:21.647 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
09:24:21.647 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authenticationManager'
09:24:21.648 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authenticationManager'
09:24:21.648 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'
09:24:21.648 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'
09:24:21.652 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' to allow for resolving potential circular references
09:24:21.700 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jasyptPasswordEncryption
09:24:21.702 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'tenantDetailsService'
Here's my Configuration for Spring Security
and the said classes
#Service
public class TenantDetailsService implements UserDetailsService {
#Autowired
private UserAccountRepo userAccountRepo;
#Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserAccount account = userAccountRepo.findByUsername(username);
if(account != null){
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority(account.getRole()));
return new TenantUserDetails(account.getUsername(),
account.getPassword(),authorities,account.getTenantCode());
}else{
throw new UsernameNotFoundException("Bad Credentials");
}
}
}
And the jasypt password encryption service
#Service
public class JasyptPasswordEncryptionService implements PasswordEncryptionService,PasswordEncoder{
private StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
#Override
public String encode(CharSequence rawPassword) {
return passwordEncryptor.encryptPassword(rawPassword.toString());
}
#Override
public boolean matches(CharSequence rawPassword,String encodedPassword) {
try{
return passwordEncryptor.checkPassword(rawPassword.toString(), encodedPassword);
}catch (EncryptionOperationNotPossibleException encryptionOperationNotPossibleException){
return false;
}
}
}
The problem was It already took me 30 mins and the build was still wasn't finish and I am stuck on that two lines. However, I changed my authentication manager to springs default authentication manager and it worked
Have I configured my authentication manager wrong?
EDIT
My existing configurations works on my windows machine, however on an ubuntu 14.04 it does not