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?
Related
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.
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.
What I'm trying to do is to run simple spring boot application inside a docker container (openjdk:8-jre) via docker-compose. The code works fine on my machine (macbook pro). The problem is when I'm trying to run the same piece of docker containers on my raspberry pi with raspbian. It's stuck just before logging Tomcat initialized with port(s): 8080 (http).
The container with spring application only does java -jar and exposes port 8080 for my another container (on port 8888) with my single page application. Does anyone had similar problem or know how to fix this?
Here are the logs for running the container on raspberrypi:
wfeservices | . ____ _ __ _ _
wfeservices | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
wfeservices | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
wfeservices | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
wfeservices | ' |____| .__|_| |_|_| |_\__, | / / / /
wfeservices | =========|_|==============|___/=/_/_/_/
wfeservices | :: Spring Boot :: (v2.0.3.RELEASE)
wfeservices |
wfeservices | 2018-08-22 20:36:24 - Starting Application v1.0-SNAPSHOT on 4b7fcb7b344c with PID 7 (/wfeservices.jar started by root in /)
wfeservices | 2018-08-22 20:36:24 - No active profile set, falling back to default profiles: default
wfeservices | 2018-08-22 20:36:28 - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#1412c2f: startup date [Wed Aug 22 20:36:28 UTC 2018]; root of context hierarchy
I had the exact same problem on AWS ECS then I realized that I had way to little memory so I increased the memory to 4096 megabytes and it worked.
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.