the springboot default log is something like following:
2020-04-06 19:34:11.323 INFO 19308 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-04-06 19:34:11.323 INFO 19308 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-04-06 19:34:11.424 INFO 19308 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-04-06 19:34:11.424 INFO 19308 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initializ
And I wrote a logback-spring.xml for setting some logger and appender for my application. However, when the logback-spring.xml exists in "resources" directory, the springboot default log will disappear. And there is only a <configuration> without any subelement in logback-spring.xml.
I have read the part of springboot document which is about logging and got the file. But I don't know how to use it...I tried to copy the element <property name="CONSOLE_LOG_PATTERN ... into my logback-spring.xml and using it as the formatter of my appender, then attaching the appender to <root>. But it can't work.
Thanks.
You need to include the base configuration in your logback-spring.xm file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="your.application.package" level="DEBUG"/>
</configuration>
Related
I read this
and this
The main ideas are that somebody has the wrong structure and components are not beeing scanned, I have a correct one.
My controller is beeing initialised normaly. I tested it debugging and seting the breakpoint on the contructor. It is beiing runned. DEspite of the that the endpoint could not be reached by my tests nor by postman, nor in the browser. I am getting a 404.
I am using gradle. structured my code like this. Already spent 3 Hours trying to fix this, but without success.
My controller looks like this.
package com.fressnapf.microservices.orderhistory.controller.impl;
#RestController
#RequestMapping("/customer")
public class OrderHistoryController implements IOrderHistoryController {
...
#Override
#ResponseStatus(value = HttpStatus.OK)
#RequestMapping(value = "/{customerid}/orders}", method = RequestMethod.GET, produces = "application/json")
public String getOrders(#PathVariable("customerid") String customerid, #RequestParam(required = false) String timeFrom,
#RequestParam(required = false) String timeTo, #RequestParam(required = false) String openOnly) {
...
}
}
Aplplication class
package com.fressnapf.microservices.orderhistory;
#SpringBootApplication()
#ImportResource({"classpath*:applicationContext.xml"})
#Configuration()
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
this is the response I am getting
{
"timestamp": "2020-03-03T16:00:33.489+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/customer/000000000/orders"
}
this is the log I am getting in the app
2020-03-03 16:59:27.595 INFO 10406 --- [ main] c.f.m.orderhistory.Application : Starting Application on debian-sgtechedge with PID 10406 (/home/sergeygerodes/projects/scporderhistoryservice/build/classes/java/main started by sgerodes in /home/sergeygerodes/projects/scporderhistoryservice)
2020-03-03 16:59:27.602 INFO 10406 --- [ main] c.f.m.orderhistory.Application : No active profile set, falling back to default profiles: default
2020-03-03 16:59:28.414 INFO 10406 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-03 16:59:28.441 INFO 10406 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16ms. Found 0 JPA repository interfaces.
2020-03-03 16:59:28.768 INFO 10406 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-03 16:59:29.035 INFO 10406 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-03 16:59:29.046 INFO 10406 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-03 16:59:29.047 INFO 10406 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-03-03 16:59:29.140 INFO 10406 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-03 16:59:29.140 INFO 10406 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1475 ms
2020-03-03 16:59:29.294 INFO 10406 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-03-03 16:59:29.405 INFO 10406 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-03-03 16:59:29.424 INFO 10406 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:orderhistory'
2020-03-03 16:59:29.517 INFO 10406 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-03-03 16:59:29.565 INFO 10406 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.9.Final}
2020-03-03 16:59:29.660 INFO 10406 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-03-03 16:59:29.741 INFO 10406 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-03-03 16:59:29.886 INFO 10406 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-03-03 16:59:29.892 INFO 10406 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-03 17:00:28.614 WARN 10406 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=59s108ms538?s586ns).
2020-03-03 17:00:28.685 WARN 10406 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-03 17:00:28.845 INFO 10406 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-03 17:00:29.052 INFO 10406 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-03 17:00:29.060 INFO 10406 --- [ main] c.f.m.orderhistory.Application : Started Application in 61.937 seconds (JVM running for 62.493)
2020-03-03 17:00:33.395 INFO 10406 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-03 17:00:33.395 INFO 10406 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-03-03 17:00:33.404 INFO 10406 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 9 ms
the whole applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="loggerService"
class="com.fressnapf.sdk.logger.service.impl.DefaultLogService" />
<bean id="dataService"
class="com.fressnapf.sdk.dataaccess.services.impl.H2DataProvider">
<constructor-arg index="0" value="${spring.datasource.url}"/>
<constructor-arg index="1" value="${spring.datasource.username}"/>
<constructor-arg index="2" value="${spring.datasource.password}"/>
</bean>
</beans>
If you copied your controller code and pasted it here...
There is a close bracket too much. I tested it on one of my controllers and it shows the same behaviour.
#RequestMapping(value = "/{customerid}/orders-->}<--"...
I have a Spring boot project that should connect with an instance of Cloud SQL with spring-cloud-gcp-starter-sql-postgresql in order to avoid the explicit use of an IP in the project.
So far, It connects well but it delayed a lot (around 30 seconds to start) because it tries to connect via SSL socket and after a lot of tries, it connects.
In the logs there is a line that says:
2020-02-19 00:10:09.809 INFO 6779 --- [ main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Default POSTGRESQL JdbcUrl provider. Connecting to jdbc:postgresql://google/test?socketFactory=com.google.cloud.sql.postgres.SocketFactory&cloudSqlInstance=XXXXXX:us-central1:test&useSSL=false with driver org.postgresql.Driver
As long as I know, the parameter useSSL=false won't work for postgresql. The correct one is ssl=false but when I try to overwrite the JDBC Url with the application.yml, It prints the following log:
2020-02-19 00:10:09.816 WARN 6779 --- [ main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Ignoring provided spring.datasource.url. Overwriting it based on the spring.cloud.gcp.sql.instance-connection-name.
I suspect that the delay is because of the SSL connection. So I have two questions:
How can I avoid the use of SSL connection? Since I am not setting a JDBC URL explicitly, I cannot use the ssl=false in the parameter.
I suspect that is delaying because the SSL Client certificate is not set. If this is the case, how can I set it? I already have the .pem but I don't know how to implement it
I add my application.yml with configurations and the mentioned log:
application.yml
spring:
cloud:
gcp:
project-id: xxxxxxx
config
sql:
instance-connection-name: xxxxxxx:us-central1:test
database-name: test
enabled: true
datasource:
username: test
password: 123456
initialization-mode: always
jpa:
hibernate:
ddl-auto: update
The credentials are set in a environment variable "GOOGLE_APPLICATION_CREDENTIALS" calling the service account json
Log:
2020-02-19 00:10:09.692 INFO 6779 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-02-19 00:10:09.699 INFO 6779 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-02-19 00:10:09.699 INFO 6779 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-02-19 00:10:09.767 INFO 6779 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-02-19 00:10:09.767 INFO 6779 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 790 ms
2020-02-19 00:10:09.809 INFO 6779 --- [ main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Default POSTGRESQL JdbcUrl provider. Connecting to jdbc:postgresql://google/test?socketFactory=com.google.cloud.sql.postgres.SocketFactory&cloudSqlInstance=XXXXXXX:us-central1:test&useSSL=false with driver org.postgresql.Driver
2020-02-19 00:10:09.816 WARN 6779 --- [ main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Ignoring provided spring.datasource.url. Overwriting it based on the spring.cloud.gcp.sql.instance-connection-name.
2020-02-19 00:10:09.885 INFO 6779 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-02-19 00:10:09.940 INFO 6779 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.10.Final}
2020-02-19 00:10:10.039 INFO 6779 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-02-19 00:10:10.109 INFO 6779 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-02-19 00:10:10.193 INFO 6779 --- [ main] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:10.193 INFO 6779 --- [ main] c.g.cloud.sql.core.CoreSocketFactory : First Cloud SQL connection, generating RSA key pair.
2020-02-19 00:10:13.690 INFO 6779 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-02-19 00:10:13.711 INFO 6779 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-02-19 00:10:13.791 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:15.042 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:16.333 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:17.653 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:19.314 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:20.643 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:21.938 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:23.227 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:24.561 INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
2020-02-19 00:10:35.164 INFO 6779 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-02-19 00:10:35.173 INFO 6779 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-02-19 00:10:35.294 WARN 6779 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-02-19 00:10:35.507 INFO 6779 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-02-19 00:10:35.611 INFO 6779 --- [ main] o.s.c.g.core.DefaultCredentialsProvider : Default credentials provider for service account cloud-code#XXXXXXX.iam.gserviceaccount.com
2020-02-19 00:10:35.612 INFO 6779 --- [ main] o.s.c.g.core.DefaultCredentialsProvider : Scopes in use by default credentials: [https://www.googleapis.com/auth/pubsub, https://www.googleapis.com/auth/spanner.admin, https://www.googleapis.com/auth/spanner.data, https://www.googleapis.com/auth/datastore, https://www.googleapis.com/auth/sqlservice.admin, https://www.googleapis.com/auth/devstorage.read_only, https://www.googleapis.com/auth/devstorage.read_write, https://www.googleapis.com/auth/cloudruntimeconfig, https://www.googleapis.com/auth/trace.append, https://www.googleapis.com/auth/cloud-platform, https://www.googleapis.com/auth/cloud-vision, https://www.googleapis.com/auth/bigquery]
2020-02-19 00:10:35.612 INFO 6779 --- [ main] o.s.c.g.a.c.GcpContextAutoConfiguration : The default project ID is XXXXXXX
2020-02-19 00:10:35.730 INFO 6779 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-02-19 00:10:35.733 INFO 6779 --- [ main] c.r.c.CloudSqlTestApplication : Started CloudSqlTestApplication in 27.027 seconds (JVM running for 27.464)
Also, just in case it helps, i am adding my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ramonparis</groupId>
<artifactId>cloud-sql-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cloud-sql-test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
</dependency>
<dependency>
........
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
there are several ways you can connect to Cloud SQL , in your case you should use a sockect
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
<version>1.0.15</version>
</dependency>
spring.datasource.url: jdbc:postgresql://google/cloudSqlInstance=${instance}&socketFactory=com.google.cloud.sql.postgres.SocketFactory
the other way is using a cloud_sql_proxy (more compless and i would indicate if you are using on GKE) Like :
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
chmod +x cloud_sql_proxy
create a proxy user :
gcloud iam service-accounts create proxy-user --display-name "proxy-account-user"
gcloud projects add-iam-policy-binding [PROJECT_ID] --member \
serviceAccount:[SERVICE_ACCOUNT_EMAIL] --role roles/cloudsql.client
gcloud iam service-accounts keys create key.json --iam-account [SERVICE_ACCOUNT_EMAIL]
./cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:5432 -credential_file=key.json &
now you are listenning to your instance db : check the video (www.youtube.com/watch?v=iKoaiH_xYB8)
I have two spring boot apps with their own application.properties.
One is in my src/main/resources as application.properties and the other as test.properties in src/test/resources.
I want it so that when I launch my spring boot app in main, it also simultaneously launches the spring boot app in my test. I want to do this in Maven command line but I was also wondering if it is possible to do in Spring Boot as well, perhaps programmatically?
The spring boot apps are running on localhost but two different ports.
The one in main is running on localhost:28433 and the other on localhost:9119.
I have tried running this mvn command:
mvn spring-boot:run -Drun.arguments="--server.port=9119""--server.port=28433"
I am not sure this works though.. when I run it in my terminal it outputs this:
t.TomcatWebServer : Tomcat initialized with port(s): 28433 (http)
2019-08-12 15:25:51.641 INFO 37469 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-12 15:25:51.641 INFO 37469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.12
2019-08-12 15:25:51.649 INFO 37469 --- [ 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/asluborski/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2019-08-12 15:25:51.707 INFO 37469 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-12 15:25:51.707 INFO 37469 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 934 ms
2019-08-12 15:25:51.731 INFO 37469 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet messageDispatcherServlet mapped to [/nulogix/ws/*]
2019-08-12 15:25:51.732 INFO 37469 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2019-08-12 15:25:51.735 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-08-12 15:25:51.735 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-08-12 15:25:51.735 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'formContentFilter' to: [/*]
2019-08-12 15:25:51.736 INFO 37469 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-08-12 15:25:51.760 DEBUG 37469 --- [ main] c.n.b.service.PredictionEngineService : billing.engine.address=127.0.0.1
2019-08-12 15:25:51.760 DEBUG 37469 --- [ main] c.n.b.service.PredictionEngineService : billing.engine.port=9119
2019-08-12 15:25:51.760 DEBUG 37469 --- [ main] c.n.b.service.PredictionEngineService : Using http://127.0.0.1:9119
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/Users/asluborski/.m2/repository/com/sun/xml/bind/jaxb-impl/2.2.11/jaxb-impl-2.2.11.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019-08-12 15:25:52.037 DEBUG 37469 --- [ main] c.n.billing.ws.endpoint.AnalyzeEndPoint : billing.engine.api.version=0.97
2019-08-12 15:25:52.038 DEBUG 37469 --- [ main] c.n.billing.ws.endpoint.AnalyzeEndPoint : billing.engine.core.version=0.97
2019-08-12 15:25:52.038 DEBUG 37469 --- [ main] c.n.billing.ws.endpoint.AnalyzeEndPoint : billing.engine.core.name=Nulogix_Patient_Responsibility
2019-08-12 15:25:52.039 DEBUG 37469 --- [ main] c.n.b.ws.endpoint.GetVersionEndPoint : billing.engine.api.version=0.97
2019-08-12 15:25:52.184 INFO 37469 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-12 15:25:52.398 INFO 37469 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 28433 (http) with context path ''
2019-08-12 15:25:52.402 INFO 37469 --- [ main] com..billing.App : Started App in 1.995 seconds (JVM running for 9.911)
It says above that it is using 127.0.0.1:9119 but it seems to only start my main App but not my test App which is specifically called mockServerApp so I do not think it is doing what I want...
How do I launch these simultaneously?
I'm can't tell what mockServerApp is being used for, but I don't think bootRun handles multiple applications or even scans your test classes.
If you want to mock an external dependency for unit testing purposes, you should wrap the calls in a proxy class of some sort and use #MockBean to inject a mock instance.
If you want to deploy a stub external dependency for development purposes, you could create a separate project for the stub as a parent directory that would invoke maven on startup. You could even implement the mock in a different framework or language.
The most straightforward option, though would be to write a shell script that launches and kills both services.
For specifying the ports, in the application.properties of each set the server.port to be an environment variable:
primary application.conf:
server.port=${MY_APP_PORT:28433}
mock application.conf:
server.port=${MOCK_APP_PORT:9119}
For launching external dependencies in integration tests, check out Testcontainers
I have a spring boot application with an embedded tomcat and make use of spring-boot-devtools to restart application if something changed in classpath.
My IDE is Spring Tool Suite and I switched of "Build Automatically" as I thought this could change files in the background which triggers the restart
My problem is that after tomcat and application ist started it immediately restart everything in an infinite loop:
2017-08-22 10:24:04.309 INFO 9772 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8055 (http)
2017-08-22 10:24:04.415 DEBUG 9772 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Creating new Restarter for thread Thread[main,5,main]
2017-08-22 10:24:04.417 DEBUG 9772 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Immediately restarting application
2017-08-22 10:24:04.418 DEBUG 9772 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader#558f3be6
2017-08-22 10:24:04.419 DEBUG 9772 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Starting application test.web.MyApplication with URLs
2017-08-22 10:24:04.421 INFO 9772 --- [ restartedMain] test.web.MyApplication : Started MyApplication in 22.347 seconds (JVM running for 24.103)
2017-08-22 10:24:05.524 DEBUG 9772 --- [ File Watcher] o.s.boot.devtools.restart.Restarter : Restarting application
2017-08-22 10:24:05.527 DEBUG 9772 --- [ Thread-9] o.s.boot.devtools.restart.Restarter : Stopping application
2017-08-22 10:24:05.527 INFO 9772 --- [ Thread-9] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#68f499a9: startup date [Tue Aug 22 10:23:43 CEST 2017]; root of context hierarchy
2017-08-22 10:24:05.529 INFO 9772 --- [ Thread-9] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2017-08-22 10:24:05.537 INFO 9772 --- [ Thread-9] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-08-22 10:24:05.539 INFO 9772 --- [ Thread-9] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2017-08-22 10:24:05.567 INFO 9772 --- [ Thread-9] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
2017-08-22 10:24:05.864 INFO 9772 --- [ost-startStop-2] org.apache.wicket.Application : [wicket-filter] destroy: DevUtils DebugBar Initializer
...
2017-08-22 10:44:04.309 INFO 9772 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8055 (http)
...
2017-08-22 10:44:04.421 INFO 9772 --- [ restartedMain] test.web.MyApplication : Started MyApplication in 22.347 seconds (JVM running for 24.103)
2017-08-22 10:44:05.527 DEBUG 9772 --- [ Thread-9] o.s.boot.devtools.restart.Restarter : Stopping application
Workaroud: I know with spring.devtools.restart.enabled = false I can stop this behaviour but of course I would like the restart if it's really necessary
Question:
How to find out which file change triggers the restart?
Anybody had similar issues?
Okay, I found the problem related to our application restart via Spring Boot DevTools after some seconds just after the application started.
The log file folder was scanned by DevTools and because the application writes logs to this folder after starting, each start triggered a reload of the whole application via DevTools.
The solution is to exclude the log folder from the monitoring within the application.yml:
spring:
devtools:
restart:
exclude: logs/**
If you´re using normal property files, it´s just the same but with (.) dots in between. See also http://www.logicbig.com/tutorials/spring-framework/spring-boot/restart-exclude/ for reference.
I have added in application.properties, then it was working fine. TQ
spring.devtools.restart.additional-exclude=logs/**
In IntelliJ Idea IDE
Edit Run/Debug Configurations... -> select your Spring Boot service item (at the left panel) -> set Running Application Update Policy:
On 'Update' action: Do nothing
On 'frame deactivation': Do nothing
Hello I am having troubles 'serving' resources with my web server, while some of my other resources are 'serving.' (graphs.js is loading)
In my browser console:
GET http://localhost:8080/js/app.js [HTTP/1.1 400 Bad Request 2ms]
GET http://localhost:8080/includes/header.html [HTTP/1.1 400 Bad Request 4ms]
GET http://localhost:8080/cs/bootstrap.min.css [HTTP/1.1 400 Bad Request 3ms]
But these files are located in my directory as such:
css/
bootstrap.min.css
includes/
header.html
js/
app.js
controllers/
graphs.js
When my server starts:
2014-07-28 08:25:06.748 INFO 5260 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-07-28 08:25:06.939 INFO 5260 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2014-07-28 08:25:06.940 INFO 5260 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-07-28 08:25:07.017 INFO 5260 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-07-28 08:25:07.017 INFO 5260 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1146 ms
2014-07-28 08:25:07.346 INFO 5260 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
**mapping**
2014-07-28 08:25:07.903 INFO 5260 --- [ main] o.s.w.s.c.a.WebMvcConfigurerAdapter : Adding welcome page: jndi:/localhost/index.html
2014-07-28 08:25:07.905 INFO 5260 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2014-07-28 08:25:07.912 INFO 5260 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-07-28 08:25:07.912 INFO 5260 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-07-28 08:25:08.023 INFO 5260 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2014-07-28 08:25:08.147 INFO 5260 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
2014-07-28 08:25:08.149 INFO 5260 --- [ main] c.c.i.qualifier.datacentral.Application : Started Application in 2.556 seconds (JVM running for 2.783)
and my HTML is like:
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/controllers/graphs.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
You have not stated if you have followed instructions for packaging as a war instead of a JAR and bundling Tomcat in. This does change things a little. Either way, take a look at the documentation here: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-mvc-static-content
Bascally, out of the box, you can place static content in one of the locations mentioned: /static, /public, /resources or /META-INF/resorces. As for the location of these folders, well either at the root of the servlet context or on the classpath.
You can find a very basic Tomcat application here: https://github.com/mmeany/spring-boot-web-mvc that does the job.