I have an spring boot application, and after it starts we usually see the following output to the console
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.0)
1283 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path
etc...
I need to get this log-output :
1283 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path
and put it to the file using slf4j
I have an application.properties with the settings of slf4j
logging.level.root=INFO
logging.level.org.spring.upskill = INFO
logging.level.org.springframework.web = INFO
logging.file.name = app.log
But I don`t get a full output to the file. Only responses to my GetMappings
For example
[2020-12-10 14:31:53.381] - 19960 INFO [main] --- org.apache.catalina.core.StandardService: Starting service [Tomcat]
[2020-12-10 14:31:53.385] - 19960 INFO [main] --- org.apache.catalina.core.StandardEngine: Starting Servlet engine: [Apache Tomcat/9.0.39]
[2020-12-10 14:31:53.432] - 19960 INFO [main] --- org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]: Initializing Spring embedded WebApplicationContext
How do I get this done?
Thank you!
I presume u can use appender.rolling.policies.startup.type = OnStartupTriggeringPolicy in properties or update the log4j2.xml to include the below inside Appenders-->RollingRandomAccessFile
<Policies>
<!-- Starts a new log on tomcat start -->
<OnStartupTriggeringPolicy />
<!-- Starts a new file when size reaches threshold -->
<SizeBasedTriggeringPolicy size="100 MB" />
<!-- causes a rollover once the date/time pattern no longer applies to
the active file
<TimeBasedTriggeringPolicy /> -->
</Policies>
Related
this is the startup log in this picture
21:20:45,691 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator#28c97a5 - Registering current configuration as safe fallback point
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.12.RELEASE)
2021-01-06 21:20:46,346 [main] INFO com.pingan.smartcity.scw.whapply.WhApplyApplication - Starting WhApplyApplication v1.0-SNAPSHOT on izxs801ql7o8q7dbxyv64jz with PID 11576 (/opt/data/app/h5/whapply-xm-1.0-SNAPSHOT.jar started by root in /opt/data/app/h5)
2021-01-06 21:20:46,349 [main] DEBUG com.pingan.smartcity.scw.whapply.WhApplyApplication - Running with Spring Boot v2.1.12.RELEASE, Spring v5.1.13.RELEASE
2021-01-06 21:20:46,349 [main] INFO com.pingan.smartcity.scw.whapply.WhApplyApplication - The following profiles are active: prod
2021-01-06 21:20:47,511 [main] WARN org.mybatis.spring.mapper.ClassPathMapperScanner - No MyBatis mapper was found in '[com.pingan.smartcity.scw.whapply]' package. Please check your configuration.
2021-01-06 21:20:47,550 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Multiple Spring Data modules found, entering strict repository configuration mode!
2021-01-06 21:20:47,552 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-01-06 21:20:47,596 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 30ms. Found 0 Redis repository interfaces.
2021-01-06 21:20:48,110 [main] INFO o.s.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$f5a22d6c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-01-06 21:36:15,587 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8899 (http)
2021-01-06 21:36:15,608 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8899"]
2021-01-06 21:36:15,622 [main] INFO org.apache.catalina.core.StandardService - Starting service [Tomcat]
2021-01-06 21:36:15,622 [main] INFO org.apache.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.30]
2021-01-06 21:36:15,710 [main] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2021-01-06 21:36:15,710 [main] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 929305 ms
As shown in the picture above, It takes 10 minutes to start my springboot application, This is very abnormal, what's the problem '
I am trying to build a proof of concept for microservices in java (eclipse) using Spring libraries and following this tutorial.
Due to certain restrictions, I am not using Maven, but I rather downloaded the following jar files manually and imported them to my java project.
My java code is very simple as the following:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
#SpringBootApplication
#EnableAutoConfiguration
public class HelloWorld {
#RequestMapping("/")
//http://localhost:port/
String hello()
{
return "Hello World!!!";
}
public static void main (String[] args) throws Exception
{
SpringApplication.run(HelloWorld.class,args);
}
}
The problem is: When I run the code, the server does NOT start, but no errors are there, except the following output, and the application shuts down instantly:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.RELEASE)
2019-08-29 09:41:17.999 INFO 14096 --- [ main] hello.HelloWorld : Starting HelloWorld on HQTPM146609D with PID 14096 (D:\Ramesh\ADMWorkspace\HelloWorldMicroservice\build\classes started by abdallah.alhodaly in D:\Ramesh\ADMWorkspace\HelloWorldMicroservice)
2019-08-29 09:41:18.002 INFO 14096 --- [ main] hello.HelloWorld : No active profile set, falling back to default profiles: default
2019-08-29 09:41:18.078 INFO 14096 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#3d36e4cd: startup date [Thu Aug 29 09:41:18 GST 2019]; root of context hierarchy
2019-08-29 09:41:19.408 INFO 14096 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-08-29 09:41:19.426 INFO 14096 --- [ main] hello.HelloWorld : Started HelloWorld in 1.86 seconds (JVM running for 2.504)
2019-08-29 09:41:19.430 INFO 14096 --- [ Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#3d36e4cd: startup date [Thu Aug 29 09:41:18 GST 2019]; root of context hierarchy
2019-08-29 09:41:19.432 INFO 14096 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
How can I fix my code so that the message Hello World!!! is displayed on the web page? Thank You.
Update: Following the below answer, I set the context of my application to WebApplicationType.SERVLET. Now, I am getting the following errors:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.RELEASE)
2019-08-29 11:03:28.515 INFO 9416 --- [ main] hello.HelloWorld : Starting HelloWorld on HQTPM146609D with PID 9416 (D:\Ramesh\ADMWorkspace\HelloWorldMicroservice\build\classes started by abdallah.alhodaly in D:\Ramesh\ADMWorkspace\HelloWorldMicroservice)
2019-08-29 11:03:28.518 INFO 9416 --- [ main] hello.HelloWorld : No active profile set, falling back to default profiles: default
2019-08-29 11:03:28.616 INFO 9416 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#62e136d3: startup date [Thu Aug 29 11:03:28 GST 2019]; root of context hierarchy
2019-08-29 11:03:29.521 WARN 9416 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2019-08-29 11:03:29.534 INFO 9416 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-29 11:03:29.542 ERROR 9416 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at hello.HelloWorld.main(HelloWorld.java:29) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
... 6 common frames omitted
In main class, you need write "SpringApplication.run(HelloWorldApplication.class,args);"
Your application context is wrong, it should of web application context. To fix this try either of these
setApplicationContextClass(…) or setWebApplicationType(WebApplicationType) using SpringApplication.
I have deployed stand alone jar on Linux server in production about 6 month ago. Its starting in about few seconds.
But when I deploy a newly builded jar on same server. It takes around 30-45 minutes for getting started.
Due to this I am not able to change any thing on existing setup.
I tried to start a Hello World spring boot app on same server. Its also taking 2 minutes for getting started.
Hello World App Logs:
[support#kbla180303 ~]$ java -jar /app/kpam/kpam-test.jar
Inside Main
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.4.RELEASE)
2019-05-09 13:26:42.606 INFO 1656 --- [ main] com.kmbl.kpam.KpamTest1Application : Starting KpamTest1Application v0.0.1-SNAPSHOT on kbla180303 with PID 1656 (/app/kpam/kpam-test.jar started by support in /home/support)
2019-05-09 13:26:43.110 INFO 1656 --- [ main] com.kmbl.kpam.KpamTest1Application : No active profile set, falling back to default profiles: default
2019-05-09 13:26:50.058 INFO 1656 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#531d72ca: startup date [Thu May 09 13:26:50 IST 2019]; root of context hierarchy
2019-05-09 13:27:52.515 INFO 1656 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-05-09 13:27:53.905 INFO 1656 --- [ main] com.kmbl.kpam.KpamTest1Application : Started KpamTest1Application in 122.87 seconds (JVM running for 164.207)
Exit Main
2019-05-09 13:27:53.907 INFO 1656 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#531d72ca: startup date [Thu May 09 13:26:50 IST 2019]; root of context hierarchy
2019-05-09 13:27:53.910 INFO 1656 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
I have updated the spring boot version from 1.5.4.RELEASE to 2.1.4.RELEASE. Now application is starting in few seconds.
But still not found the root cause for this issue.
There is good question about ability to add multiple tomcat connectors and bind them to separate controllers each.
The essense of Andy Wilkinson's good answer is here:
public static void main(String[] args) {
SpringApplicationBuilder parentBuilder
= new SpringApplicationBuilder(ApplicationConfiguration.class);
parentBuilder.child(ServiceOneConfiguration.class)
.properties("server.port:8080").run(args);
parentBuilder.child(ServiceTwoConfiguration.class)
.properties("server.port:8081").run(args);
}
I want to go on this futher and ask another question:
Is there a way to make each child application context to read some child specific application properties with support of all standard spring-boot's features, like profile-suffix file names etc.
One hypothetical way to achieve it:
Have three separate property files:
application.properties
child1.properties
child2.properties
And have ability to set one file for each context.
But what is important to me, that they must support all spring-boot magic. For example, if I activate new profile like passing command line argument --spring.profiles.active=dev, then automagically not only these three files should be loaded (one for each context), but another set of files (if they exist) also should be loaded automatically:
application-dev.properties
child1-dev.properties
child2-dev.properties
Of course, these files should be searched at standard spring-boot's supported paths in defined order etc.
Is it possible out if the box of maybe with some coding?
Another hypothetical way to achieve it
Have only one application.properties file (with support for profiles etc), but somehow to map prefixed properties to unprefixed properties of child contexts.
Example:
child1.server.port=8081
child1.foo=bar
child2.server.port=8082
child2.foo=baz
First child context should see these properties like if they were just:
server.port=8081
foo=bar
Second child context should see these properties like if they were just:
server.port=8082
foo=baz
So, standard spring-boot's autoconfigurations will work and correctly set tomcat's port etc.
I am not looking for specific approach (but if you ask me, I'm leaning towards second approach), but any working out-of-the-box or achievable with minimum conding apporach will suffice me.
You can achieve your first suggestion using spring.config.name:
public static void main(String[] args) {
SpringApplicationBuilder parentBuilder =
new SpringApplicationBuilder(ParentApplication.class)
.web(WebApplicationType.NONE);
parentBuilder.run(args);
parentBuilder.child(ServiceOneConfiguration.class)
.properties("spring.config.name=child1").run(args);
parentBuilder.child(ServiceTwoConfiguration.class)
.properties("spring.config.name=child2").run(args);
}
You can then use child1{-profile}.properties and child2{-profile}.properties to configure service one and service two respectively.
For example, with server.port=8081 in child1.properties and server.port=8082 in child2.properties, you should see output similar to the following when starting an app that's using auto-configuration in the two child services and has a dependency on spring-boot-starter-web:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2019-01-22 13:38:09.690 INFO 80968 --- [ main] com.example.parent.ParentApplication : Starting ParentApplication on …
2019-01-22 13:38:09.692 INFO 80968 --- [ main] com.example.parent.ParentApplication : No active profile set, falling back to default profiles: default
2019-01-22 13:38:09.842 INFO 80968 --- [ main] com.example.parent.ParentApplication : Started ParentApplication in 0.371 seconds (JVM running for 0.644)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2019-01-22 13:38:10.046 INFO 80968 --- [ main] com.example.parent.ParentApplication : No active profile set, falling back to default profiles: default
2019-01-22 13:38:10.584 INFO 80968 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2019-01-22 13:38:10.604 INFO 80968 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-01-22 13:38:10.605 INFO 80968 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-01-22 13:38:10.613 INFO 80968 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/awilkinson/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2019-01-22 13:38:10.668 INFO 80968 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-01-22 13:38:10.668 INFO 80968 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 612 ms
2019-01-22 13:38:10.829 INFO 80968 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-01-22 13:38:10.981 INFO 80968 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2019-01-22 13:38:10.981 INFO 80968 --- [ main] com.example.parent.ParentApplication : Started ParentApplication in 0.955 seconds (JVM running for 1.784)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2019-01-22 13:38:11.003 INFO 80968 --- [ main] com.example.parent.ParentApplication : No active profile set, falling back to default profiles: default
2019-01-22 13:38:11.093 INFO 80968 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8082 (http)
2019-01-22 13:38:11.095 INFO 80968 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-01-22 13:38:11.096 INFO 80968 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-01-22 13:38:11.100 INFO 80968 --- [ main] o.a.c.c.C.[Tomcat-1].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-01-22 13:38:11.101 INFO 80968 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 97 ms
2019-01-22 13:38:11.135 INFO 80968 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-01-22 13:38:11.164 INFO 80968 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8082 (http) with context path ''
2019-01-22 13:38:11.165 INFO 80968 --- [ main] com.example.parent.ParentApplication : Started ParentApplication in 0.183 seconds (JVM running for 1.967)
I am using spring-boot-starter-parent 1.4.3.RELEASE and wrote test cases using mockito-all 2.0.2-beta. After using #MockBean My spring started twice..
2017-02-08 12:03:11.135 INFO 9375 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$61cd4862] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.3.RELEASE)
2017-02-08 12:03:11.268 INFO 9375 --- [ main] c.v.d.chain.PublisherChainResourceTest : No active profile set, falling back to default profiles: default
2017-02-08 12:03:11.271 INFO 9375 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.springframework.web.context.support.GenericWebApplicationContext#101d4a4e: startup date [Wed Feb 08 12:03:11 IST 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#4adfb1f
........................
2017-02-08 12:03:24.109 INFO 9375 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$61cd4862] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.3.RELEASE)
2017-02-08 12:03:24.267 INFO 9375 --- [ main] c.v.d.t.AdNetworkParamResourceTest : No active profile set, falling back to default profiles: default
2017-02-08 12:03:24.272 INFO 9375 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.springframework.web.context.support.GenericWebApplicationContext#7fcc9949: startup date [Wed Feb 08 12:03:24 IST 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#17660e9a
My application.yml,
spring:
datasource:
url: jdbc:hsqldb:mem:testdb;sql.syntax_mys=true
username:
password:
driver-class-name: org.hsqldb.jdbcDriver
testOnBorrow: true
validationQuery: SELECT 1
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
format_sql: true
show_sql: true
endpoints:
health:
sensitive: false
server:
tomcat:
basedir: target/tomcat
accesslog:
enabled: true
pattern: "%v %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" %S %D"
liquibase:
user:
password:
default-schema: your_schema
enabled: false
How to solve this?
Why the spring starts twice when I run "mvn clean install"
My test as follows..
#RunWith(SpringRunner.class)
#SpringBootTest(classes = ConfigMyApplication.class)
#WebAppConfiguration
public class XXResourceTest extends AbstractTransactionalJUnit4SpringContextTests {
private static final String PATH = "/xxxxxxx/";
#Autowired
XXXXXRepository xxxxxRepository;
#MockBean
#Autowired
XXXXXApiService xxxxxApiService;
#Autowired
WebApplicationContext webApplicationContext;
MockMvc mockMvc;
HttpHeaders headers;
int xxxId = 1;
int parentId = 1;
#Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
MockitoAnnotations.initMocks(this);
headers = new HttpHeaders();
headers.add(CONTENT_TYPE, APPLICATION_JSON);
}
#Test
public void createXXXTest() throws JsonProcessingException, Exception {
DtoInput input = new DtoInput();
input.setXXXId(xxxId);
input.setParentId(parentId);
Parent parent = new Parent();
parent.setId(parentId);
when(xxxxxApiService.getParent(parentId)).thenReturn(parent);
mockMvc.perform(post(PATH).content(new ObjectMapper().writeValueAsString(input)).headers(headers))
.andDo(print()).andExpect(status().isCreated())
.andExpect(jsonPath("$.xxId", is(xxId)))
.andExpect(jsonPath("$.type", is("type")))
.andExpect(jsonPath("$.parentId", is(parentId)));
}
You have multiple tests with different spring-contexts, so a new context is started for each.
Spring will cache contexts between tests if they are identical, but if you have different beans/config then it needs to create multiples.