I have 16 Unit test case files. Each in this format:
#SpringBootTest
class UserServiceTest {
#Autowired
UserService userService;
#MockBean
SomeDependency someDependency;
#Test
...and so on
}
Whenever I run mvn clean install, it seems that spring is restarting/loading context 16 times. I see these logs 16 times:
[INFO] Running com.base.UserServiceTest
2021-07-16 04:35:39.421 [INFO ] [main] o.s.t.c.s.AbstractTestContextBootstrapper - Neither #ContextConfiguration nor #ContextHierarchy found for test class [com.base.UserServiceTest], using SpringBootContextLoader
2021-07-16 04:35:39.423 [INFO ] [main] o.s.t.c.s.AbstractContextLoader - Could not detect default resource locations for test class [com.base.UserServiceTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2021-07-16 04:35:39.424 [INFO ] [main] o.s.t.c.s.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.base.UserServiceTest]: UserServiceTest does not declare any static, non-private, non-final, nested classes annotated with #Configuration.
2021-07-16 04:35:39.473 [INFO ] [main] o.s.b.t.c.SpringBootTestContextBootstrapper - Found #SpringBootConfiguration com.base.Application for test class com.base.UserServiceTest
2021-07-16 04:35:39.475 [INFO ] [main] o.s.t.c.s.AbstractTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
2021-07-16 04:35:39.476 [INFO ] [main] o.s.t.c.s.AbstractTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener#4dc599a7, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener#635f2d9b, org.springframework.test.context.event.ApplicationEventsTestExecutionListener#7e83380f, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener#6000fc20, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener#1e95926, org.springframework.test.context.support.DirtiesContextTestExecutionListener#1bc08f75, org.springframework.test.context.transaction.TransactionalTestExecutionListener#7ce49f42, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener#1b629d02, org.springframework.test.context.event.EventPublishingTestExecutionListener#5089c721, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener#4fad5162, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener#176bd95a, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener#186edc38, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener#6c0b0db, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener#2343c720, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener#6aab6b1b]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.0)
2021-07-16 04:35:39.520 [INFO ] [main] o.s.b.StartupInfoLogger - Starting UserServiceTest using Java 11.0.2 on
2021-07-16 04:35:39.523 [INFO ] [main] o.s.b.SpringApplication - The following profiles are active: local
2021-07-16 04:35:40.197 [INFO ] [main] o.s.m.w.MockServletContext - Initializing Spring TestDispatcherServlet ''
2021-07-16 04:35:40.197 [INFO ] [main] o.s.w.s.FrameworkServlet - Initializing Servlet ''
2021-07-16 04:35:40.199 [INFO ] [main] o.s.w.s.FrameworkServlet - Completed initialization in 1 ms
2021-07-16 04:35:40.211 [INFO ] [main] o.s.b.StartupInfoLogger - Started UserServiceTest in 0.732 seconds (JVM running for 9.613)
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.918 s - in com.base.UserServiceTest
This causes 2 problems:
There are a lot more tests to be added. Even with 16 test files, it takes around 20 seconds to execute. So the process is slow.
My application uses JPA to connect with DB, and during mvn clean install, although the application builds successfully, it gives this error in logs random number of times:
2021-07-16 04:35:52.741 [ERROR] [main] c.z.h.p.HikariPool - HikariPool-11 - Exception during pool initialization. org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections
I wonder if this context reloading is causing this as I perform mvn clean install often and that there might be a connection leak somewhere.
Using JUnit 5/Jupiter and Spring 5.
Any help in fixing above 2 points is appreciated. Thanks.
Spring Test caches your TestContext and re-uses it for another test if the context configuration fits.
However, if all your tests have a different setup (e.g., the first test wants a mocked version of class A and the second test wants a mocked version of class B), caching won't help and Spring has to start a new context.
If you streamline the context setup for all your tests, Spring will reuse it and hence make the test execution fast.
In addition, the test you added (using #SpringBootTest) is not a unit test (well - it always depends on the definition) as it starts the entire Spring context.
If your plan is to write unit tests for your business logic, rather use just JUnit 5 and Mockito. These tests are fast and there's no Spring support and hence no context started.
For a broad overview of unit, integration, and end-to-end testing strategies for Spring Boot applications, take a look at this article.
Related
According to Docker official website , Docker doesn't support SQL image for M1 processors ; however , it supports installing it by passing " --platform linux/x86_64 mysql" .
Actually , SQL docker is pulled successfully using this command
docker pull --platform linux/x86_64 mysql
the output :
Using default tag: latest
latest: Pulling from library/mysql
a330b6cecb98: Pull complete
9c8f656c32b8: Pull complete
88e473c3f553: Pull complete
062463ea5d2f: Pull complete
daf7e3bdf4b6: Pull complete
1839c0b7aac9: Pull complete
cf0a0cfee6d0: Pull complete
1b42041bb11e: Pull complete
10459d86c7e6: Pull complete
b7199599d5f9: Pull complete
1d6f51e17d45: Pull complete
50e0789bacad: Pull complete
Digest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:late
Now , I want to use SQL container in my integration test , but docker fails to pull SQL.
The code used to initialize SQL test container
#DynamicPropertySource
static void dynamicPropertySource(DynamicPropertyRegistry dynamicPropertyRegistry) {
MySQLContainer<?> container = new MySQLContainer<>("mysql:8.0.26")
.withDatabaseName("sympl")
.withUsername("test")
.withPassword("test")
.withCommand("docker pull --platform linux/x86_64 mysql");
dynamicPropertyRegistry.add("spring.datasource.url", () -> container.getJdbcUrl());
dynamicPropertyRegistry.add("spring.datasource.username", () -> container.getUsername());
dynamicPropertyRegistry.add("spring.datasource.password", () -> container.getPassword());
container.start();
}
I tried to write the code withCommand() and without .withCommand.
After I run the test cases , it gives fails with the following logs :
17:18:25.003 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.003 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.005 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.005 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.015 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext#3faf2e7d testClass = CustomerApiIntegrationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration#4648ce9 testClass = CustomerApiIntegrationTests, locations = '{}', classes = '{class com.sympl.customer.CustomersApplication}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer#78fa769e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer#2c78324b, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer#3fd11d55, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer#6ca18a14, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer#1ec9bd38, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer#0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer#cd1e646, org.springframework.test.context.support.DynamicPropertiesContextCustomizer#aa1b54d2, org.springframework.boot.test.context.SpringBootTestArgs#1, org.springframework.boot.test.context.SpringBootTestWebEnvironment#5890e879], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> false]], class annotated with #DirtiesContext [false] with mode [null].
17:18:25.021 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.021 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sympl.customer.api.CustomerApiIntegrationTests]
17:18:25.088 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profiles [test]
17:18:25.094 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.3)
2021-09-19 17:18:26.039 INFO 9715 --- [ main] o.t.d.DockerClientProviderStrategy : Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
2021-09-19 17:18:27.294 INFO 9715 --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
2021-09-19 17:18:27.299 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is localhost
2021-09-19 17:18:27.365 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
Server Version: 20.10.8
API Version: 1.41
Operating System: Docker Desktop
Total Memory: 1988 MB
2021-09-19 17:18:27.369 INFO 9715 --- [ main] o.t.utility.ImageNameSubstitutor : Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2021-09-19 17:18:27.547 INFO 9715 --- [ main] o.t.utility.RegistryAuthLocator : Credential helper/store (docker-credential-desktop) does not have credentials for index.docker.io
2021-09-19 17:18:28.202 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
2021-09-19 17:18:28.203 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : Checking the system...
2021-09-19 17:18:28.203 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : 鉁旓笌 Docker server version should be at least 1.6.0
2021-09-19 17:18:28.322 INFO 9715 --- [ main] org.testcontainers.DockerClientFactory : 鉁旓笌 Docker environment should have more than 2GB free disk space
2021-09-19 17:18:28.388 INFO 9715 --- [ main] 馃惓 [mysql:8.0.26] : Pulling docker image: mysql:8.0.26. Please be patient; this may take some time but only needs to be done once.
2021-09-19 17:18:32.326 INFO 9715 --- [stream--1235448] 馃惓 [mysql:8.0.26] : Starting to pull image
2021-09-19 17:18:32.369 INFO 9715 --- [stream--1235448] 馃惓 [mysql:8.0.26] : Pulling image layers: 0 pending, 0 downloaded, 0 extracted, (0 bytes/0 bytes)
2021-09-19 17:18:32.422 ERROR 9715 --- [ main] o.s.boot.SpringApplication : Application run failed
org.testcontainers.containers.ContainerLaunchException: Container startup failed
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:330) ~[testcontainers-1.15.3.jar:na]
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311) ~[testcontainers-1.15.3.jar:na]
at com.sympl.customer.api.CustomerApiIntegrationTests.dynamicPropertySource(CustomerApiIntegrationTests.java:79) ~[test-classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
Here is the docker logs
I am sure there is a workaround for this , but I couldn't find it till now .
I'm the current PM for Azure SQL Edge at Microsoft dropping by with an update to share. Docker Desktop v4.16 introduced beta support for the Virtualization framework, meaning you can now run x86/amd64 based SQL Server containers on M1/M2 silicon with macOS 13. This will be our recommended path for running SQL server containers on ARM based macOS going forward as it will enable you to develop against SQL Server 2017-2022 in addition to Azure SQL Edge. For a walkthrough on how to enable the feature and run a SQL Server 2022 container on macOS, check out https://devblogs.microsoft.com/azure-sql/development-with-sql-in-containers-on-macos/
Not found anything interesting so far, so here am I, asking a question.
I got a spring boot application, that runs fine. Problem is : custom configuration !
I want it to run on port 8081 (and not default port 8080). So I added the application.yml in the src/main/resources directory, packaged it... And it run on port 8080
When I run the #SpringBootApplication class from intellij, it does run on port 8081 (I just added the application.yml file.) So why ?
It's a gradle multi module project. T added the application.yml file into the module that is actually packaged into a jar file. It is packaged using tha gradle shadow plugin, and does contain the application.yml file at the root of the jar file.
The application.yml is like this :
server:
port: 8081
I don't really know which information you'll need, so feel free to ask !
Any idea is welcome.
EDIT 1 :
"Stacktrace" when I start the server :
java -jar serverApp.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
ao没t 29, 2020 5:50:54 PM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["http-nio-8080"]
ao没t 29, 2020 5:50:54 PM org.apache.catalina.core.StandardService startInternal
INFOS: Starting service [Tomcat]
ao没t 29, 2020 5:50:54 PM org.apache.catalina.core.StandardEngine startInternal
INFOS: Starting Servlet engine: [Apache Tomcat/9.0.37]
ao没t 29, 2020 5:50:54 PM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring embedded WebApplicationContext
ao没t 29, 2020 5:50:55 PM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-nio-8080"]
Without seeing the actual code, I can recommend 2 things to try.
1- Have you missed to use the argument in main method-
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
2- Try to start the springboot server with arguments-
java -jar -Dserver.port=8081 ServerApplication.jar
It seems that Shadow Plugin is not the right thing to use with Spring Boot according to this comment:
the boot framework has it's own gradle plugin and method for packaging ditributable jar files. I dont' think I would combine shadow and the boot plugin in the same project. They will collide.
and also this.
I'm having trouble deploying my Spring Boot application on the Google Cloud Platform Flexible environment.
I run the following command to deploy: mvn clean compile package -DskipTests appengine:deploy -P cloud-gcp
The cloud-gcp profile in my pom.xml has the following:
<profiles>
<profile>
<id>cloud-gcp</id>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<version>beta3</version>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This is my app.yaml file located at src/main/appengine/app.yaml:
runtime: java
env: flex
runtime_config:
jdk: openjdk8
env_variables:
SPRING_PROFILES_ACTIVE: "gcp"
handlers:
- url: /.*
script: this field is required, but ignored
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 4
disk_size_gb: 10
Here is my application-gcp.properties:
server.address=0.0.0.0
server.port=8080
# Datasource
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.url=jdbc:postgresql://google/xxx?cloudSqlInstance=xxx:europe-west4:xxx&autoReconnect=true&user=xxx&password=xxx&socketFactory=com.google.cloud.sql.postgres.SocketFactory&useSSL=false
server.error.whitelabel.enabled=false
# Optimize start of application
spring.jmx.enabled=false
# Gcp configuration
spring.cloud.gcp.sql.enabled=false
spring.cloud.gcp.sql.database-name=xxx
spring.cloud.gcp.sql.instance-connection-name=xxx:europe-west4:xxx
spring.cloud.gcp.logging.enabled=true
The compilation is successful, no problems there. The problem occurs when I want to access my Spring Boot application. I constantly get a 502 Error. There is nothing in the logs that gives me a clue on what is wrong:
A 2020-01-20T16:14:17Z . ____ _ __ _ _
A 2020-01-20T16:14:17Z /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
A 2020-01-20T16:14:17Z ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
A 2020-01-20T16:14:17Z \\/ ___)| |_)| | | | | || (_| | ) ) ) )
A 2020-01-20T16:14:17Z ' |____| .__|_| |_|_| |_\__, | / / / /
A 2020-01-20T16:14:17Z =========|_|==============|___/=/_/_/_/
A 2020-01-20T16:14:17Z :: Spring Boot :: (v2.1.5.RELEASE)
com.xxx.api.xxxApplication : Starting xxxApplication v0.0.1-SNAPSHOT on bc233766746a with PID 1 (/app.jar started by root in /)
com.xxx.api.xxxApplication : The following profiles are active: gcp
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
.s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 532ms. Found 17 repository interfaces.
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$2c4dbf14] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$c4fb874e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#6b00f608' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$e9d02a00] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$abce0c46] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
o.apache.catalina.core.StandardService : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.19]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 11326 ms
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
Connecting to Cloud SQL instance [xxx:europe-west4:xxx] via SSL socket.
First Cloud SQL connection, generating RSA key pair.
This is the last lines I have in the logs. Nothing seems to break, no errors as far as I can tell. It seems to correctly connect to the Cloud SQL instance. I'm lost here. I've tried a lot of things, but I always get a 502 request from Spring Boot no matter what.
For information, the /liveness_check and /readiness_check always return 200 even when the server is not launched (which is strange...).
Tell me if you need any more informations on the configuration I am using.
Thank you in advance!
We finally solved our issue. For those who might have the same issue:
The problem was caused by our guava version. We add the version 18.0, which was problematic apparently. We added the following dependencies in the pom.xml:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
</dependency>
And the problem was solved :)
Wow, just doing some venting here but have been pulling my hair out for about 2 weeks now attempting to deploy a spring boot app to google cloud. It's incredibly nerve wracking to hear that a modification of a guava dependency could cause an application to not startup - even far worse make the logs go silent with no trace of what is going on. At the moment, I too am dealing with a situation where there are no application logs to be found and no trace of what is going wrong while just simply trying to hit an endpoint after what google cloud tells me is a successful deploy.
This comment and I'm sure to write others in the future is more aimed at getting other people to vent their frustration as google cloud support is non-existent unless you pay a premium for it. Making matters worse the product appears to be just plain terrible in terms of allowing developers insights into what is actually going wrong when a deployment doesn't work. I hope this gets their attention and I hope others voice their frustration as well because this product is simply unusable when it gives no indication of what is going wrong with a deployment. I've scoured their docs to no avail and it seems others have similar issues. Unfortunately my hands are tied by my client to use google cloud otherwise I would have migrated away from it after seeing first hand some of the very basic ways it is flawed. If you're in the process of evaluating a cloud product I would highly recommend not using google.
I am currently learning how to boot a web application with a java agent for monitoring.
The Web Application I chose was WebGoat, and running WebGoat with java -jar webgoat-server-8.0.0.M17.jar as stated in WebGoat's README works perfectly fine.
However, when I try to add my agent, I get the following mess of an error log:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.12.RELEASE)
2018-06-06 22:36:08.528 INFO 3741 --- [ main] org.owasp.webgoat.StartWebGoat : Starting StartWebGoat v8.0.0.M17 on MacBook-Pro.local with PID 3741 (/Users/andrewfan/Desktop/Lang Agent Dev Proj help info/webgoat-server-8.0.0.M17.jar started by andrewfan in /Users/andrewfan/Desktop/Lang Agent Dev Proj help info)
2018-06-06 22:36:08.531 INFO 3741 --- [ main] org.owasp.webgoat.StartWebGoat : No active profile set, falling back to default profiles: default
2018-06-06 22:36:08.844 INFO 3741 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1376c05c: startup date [Wed Jun 06 22:36:08 EDT 2018]; root of context hierarchy
2018-06-06 22:36:11.354 INFO 3741 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$8e12590a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-06-06 22:36:11.442 WARN 3741 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'webgoat.user.directory' in value "${webgoat.user.directory}"
2018-06-06 22:36:11.455 INFO 3741 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-06-06 22:36:11.464 ERROR 3741 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'webgoat.user.directory' in value "${webgoat.user.directory}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.16.RELEASE.jar!/:4.3.16.RELEASE]
at
...
I cut the error messages short since the trace is a few pages long, but the main error seems to be org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'webgoat.user.directory' in value "${webgoat.user.directory}"
I am running my agent as follows:
java -javaagent:/Users/path/to/jar/Spn-LangAgent-0.0.jar -jar webgoat-server-8.0.0.M17.jar --server.port=8080 --server.address=localhost
My agent is as follows:
package com.spnlangagent.langagent;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.reflect.Field;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import com.google.monitoring.runtime.instrumentation.AllocationRecorder;
public class LangAgent {
public static void premain(String agentArgs, Instrumentation inst) throws Exception {
System.out.println("LangAgent: premain now running");
setupInstrumentation(agentArgs, inst);
startRuntime(agentArgs);
}
private static void setupInstrumentation(String agentArgs, Instrumentation inst) throws Exception {
System.out.println("setupInstrumentation: now running with agentArgs: " + agentArgs);
}
private static void startRuntime(String agentArgs) throws Exception {
System.out.println("startRuntime: now running with agentArgs: " + agentArgs);
}
}
The original contents of the agent were commented out except for a few print statements, and yet even with this, WebGoat is crashing on startup.
I tried another agent with WebGoat and it worked fine, so the only thing I can think of is that something is wrong with either my agent, or the way it is being packaged.
I am using Maven, and my MANIFEST.MF is as follows:
Manifest-Version: 1.0
Premain-Class: com.spnlangagent.langagent.LangAgent
Can-Redefine-Classes: true
Can-Retransform-Classes: true
After running mvn package, the MANIFEST packaged in the .jar is as follows:
Manifest-Version: 1.0
Premain-Class: com.spnlangagent.langagent.LangAgent
Built-By: andrewfan
Can-Redefine-Classes: true
Can-Retransform-Classes: true
Created-By: Apache Maven 3.5.3
Build-Jdk: 1.8.0_172
In my pom.xml, I am doing the following to reach the manifest:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
If someone could point me in the right direction in regards to figuring out why WebGoat is crashing, or if someone could provide more insight into why what I am currently doing is wrong, that would be greatly appreciated.
Thank you.
Note: If the rest of my pom.xml is necessary for debugging, I will gladly provide it; it's just that the question is already very long as-is.
Webgoat (and also in most Spring-based application) relies on properties file (in properties or yaml format usually) to perform placeholder lookup.
The symptom in your failure indicate that Spring failed to lookup properties for placeholder processing.
Given that placeholder lookup works well without presence of your agent JAR, and with information you mentioned in comment, the problem is caused by
Your agent JAR provided application.properties (which has name collision with the properties file used by Webgoat for placeholder)
Agent JAR will be part of classpath, and probably even appear earlier than the main JAR
your empty application.properties "shadowed" the one in Webgoat main JAR. Which means, when Webgoat starts, Spring picked up your empty application.properties for its placeholder processing, hence failed.
The solution was mvn clean
Earlier I had an application.properties that was automatically added as part of the Spring Boot Initializr. The very presence of this file in my agent .jar, even with nothing inside, seems to have been the reason why WebGoat freaked out. Now that it is no longer present, WebGoat is running normally via java -javaagent:/Users/path/to/jar/Spn-LangAgent-0.0.jar -jar webgoat-server-8.0.0.M17.jar --server.port=8080 --server.address=localhost
I'd like to thank Adrian Shum for mentioning application.properties, since I had removed it a while back. mvn package didn't actually rebuild the .jar when I ran it, so the jar I had been testing on was the one that still contained application.properties.
i have a strange problem. I have created a spring application with some functional logic and started it locally - it worked.
Then i have exported my whole project to a .war file and build a docker image to run it also locally - it worked.
Since ca. 2 day...i guess i did some changes...i want to build and run my docker file again, but stops always at this point:
Launching defaultServer (WebSphere Application Server 17.0.0.2/wlp-1.0.17.cl170220170523-1818) on IBM J9 VM, version pxa6480sr4fp10-20170727_01 (SR4 FP10) (en_US)
[AUDIT ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT ] CWWKE0100I: This product is licensed for development, and limited production use. The full license terms can be viewed here: https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/base_ilan/ilan/17.0.0.2/lafiles/en.html
[AUDIT ] CWWKG0093A: Processing configuration drop-ins resource: /opt/ibm/wlp/usr/servers/defaultServer/configDropins/defaults/keystore.xml
[WARNING ] CWWKS3103W: There are no users defined for the BasicRegistry configuration of ID com.ibm.ws.security.registry.basic.config[basic].
[AUDIT ] CWWKZ0058I: Monitoring dropins for applications.
[AUDIT ] CWWKS4104A: LTPA keys created in 6.228 seconds. LTPA key file: /opt/ibm/wlp/output/defaultServer/resources/security/ltpa.keys
[AUDIT ] CWPKI0803A: SSL certificate created in 8.761 seconds. SSL key file: /opt/ibm/wlp/output/defaultServer/resources/security/key.jks
[AUDIT ] CWWKI0001I: The CORBA name server is now available at corbaloc:iiop:localhost:2809/NameService.
[AUDIT ] CWWKT0016I: Web application available (default_host): http://2b88d6a3093b:9080/xxxxxx/
[AUDIT ] CWWKZ0001I: Application xxxxx started in 1.828 seconds.
[AUDIT ] CWWKF0012I: The server installed the following features: [servlet-3.1, beanValidation-1.1, ssl-1.0, jndi-1.0, jca-1.7, ejbPersistentTimer-3.2, appSecurity-2.0, j2eeManagement-1.1, jdbc-4.1, wasJmsServer-1.0, jaxrs-2.0, javaMail-1.5, cdi-1.2, webProfile-7.0, jcaInboundSecurity-1.0, jpa-2.1, jsp-2.3, ejbLite-3.2, managedBeans-1.0, jsf-2.2, ejbHome-3.2, jaxws-2.2, jsonp-1.0, el-3.0, jaxrsClient-2.0, concurrent-1.0, appClientSupport-1.0, ejbRemote-3.2, javaee-7.0, jaxb-2.2, mdb-3.2, jacc-1.5, batch-1.0, ejb-3.2, json-1.0, jaspic-1.1, jpaContainer-2.1, distributedMap-1.0, websocket-1.1, wasJmsSecurity-1.0, wasJmsClient-2.0].
[AUDIT ]
CWWKF0011I: The server defaultServer is ready to run a smarter planet.
My Spring application doesn't start anymore. In general it would continue with this:
2017-10-05 13:34:46.723 INFO 11136 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#c3c60d: startup date [Thu Oct 05 13:34:46 CEST 2017]; root of context hierarchy
2017-10-05 13:34:47.070 INFO 11136 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-10-05 13:34:47.112 INFO 11136 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$240b40b3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.2.RELEASE)
........
If i start my application locally from eclipse, it still works without any problems, but of course i want to build the docker image again.
Where do i have to search, if the SpringApplication start locally from the environment, but not from the docker images/container. Here it stops at
"The server defaultServer is ready to run a smarter planet."
Thank you in adnvance!
----------------- UPDATE -----------------
I found something. My exported .war file has just a size of 134kb. I am sure, it was ca. 35mb before. Does anyone has an idea?