Accessing a simple get endpoint of a Spring App deployed to a tomcat running in a container in a AWS AC2 instance - spring

I'm trying to deploy a simple spring application (https://github.com/rmmcosta/SampleRestWar.git) to a tomcat server running in a docker container inside an AWS EC2 instance.
I can generate the war file by using maven and following the instructions in this article:
https://www.baeldung.com/spring-boot-war-tomcat-deploy
I copy the war file to the /usr/local/tomcat/webapps folder inside the container and I run the catalina.sh.
I can see the following message:
05-Dec-2022 22:33:32.604 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/SampleRest.war]
05-Dec-2022 22:33:32.756 WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [5.0]. Default version will be used.
05-Dec-2022 22:33:34.512 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
05-Dec-2022 22:33:34.519 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/SampleRest.war] has finished in [1,915] ms
But when I try to access the rest enpoint or the app url I'm getting a 404.
Can you help in understanding what I'm doing wrong.
Thank you in advance.
I tried different apps with different spring versions but I'm getting the same 404 everytime.
I can see tomcat is running and the example apps already present in there are working fine.

Related

Spring boot - Unsupported config data location 'optional:file:./config/*/'

We are migrating a spring boot application from 2.2.4 to 2.4.3
The application can be run with inbuilt tomcat / Tomcat war deployment.
Environment: Windows Azul Java 11 (Zulu 11) and Tomcat 9.0.33
If I run the code with my Netbeans linked tomcat, it works fine.
If I deploy the generated war directly in the same standalone tomcat, it throws the following error.
SEVERE [main] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [D:\apache-tomcat-9.0.33-without port - rest.war]
java.lang.IllegalStateException: Error starting child
................................................................
................................................................
Caused by: org.springframework.boot.context.config.UnsupportedConfigDataLocationException: Unsupported config data location 'optional:file:./config/*/'
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:110)
On reading through the Spring document, it was mentioned that By default, Spring Boot includes config/*/ in the default search locations. Ref: https://docs.spring.io/spring-boot/docs/2.4.0-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-files-wildcards
I further debugged with spring boot source and spring core source and identified that there is a mismatch in the classloader that happens that was the cause of this exception.
SpringFactoriesLoader is the class that gets loaded by ParallelWebAppClassLoader in NB linked tomcat and by URLClassLoader in standalone tomcat.
Ref: Line No 129 at https://github.com/spring-projects/spring-framework/blob/master/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java#L129
The cache at Line 136 has the config classes loaded by ParallelWebAppClassLoader, but not by the URLlassLoader. So the 2 resolvers - ConfigTreeConfigDataLocationResolver, StandardConfigDataLocationResolver in boot v2.4.3 are not getting identified when it tries to retrieve with the key URLlassLoader (Line 136).
Not sure whether this is an issue with Springboot / SpringCore / Tomcat / any new configuration to be added as a part of our upgrade.
Note: Our application.properties has spring.servlet.multipart related properties only.
"./" is not getting resolved in standalone tomcat.
Try using classpath:application.properties , or classpath:config/* -- this would require props inside war.
or absolute path of file:/var/myapp/config/*. Since tomcat is in D:, you may create a folder d:/var/myapp/config/.
Note that within spring you can ignore "d:" and just mention "/var/myapp/config/*", so, in-case tomcat is in "x:" your code need not change.
This was an issue in Spring boot.
Updating to version 2.4.6 will solve this issue.

Issue while debugging dspace 6.0 jspui application on intellij

I have tried to configure dspace 6.0 on Intellij .But while debugging application I am getting below error.I think while configuring tomcat 7 on Intellij dspace-dir value is overridden.
Please suggest what change i need to make in configuration.
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
log4j:ERROR Could not read configuration file from URL [file:/E:/apache-tomcat-7.0.96/bin/$%7Bdspace.dir%7D/config/log4j-solr.properties].
java.io.FileNotFoundException: E:\apache-tomcat-7.0.96\bin\${dspace.dir}\config\log4j-solr.properties (The system cannot find the path specified
)
Reference link :
IntelliJ IDEA 13 setup for DSpace development on Mac OS XIntelliJ IDEA 13 setup for DSpace development on Mac OS X
https://youtu.be/mrLl1qPsy6I
Assuming that the log snippet you posted comes from the tomcat or DSpace log, when trying to start up DSpace, the causes could be:
dspace.dir value not filled out
maven or ant commando's not executed successfully. They have to be completed before starting up DSpace will work.

java.lang.NoClassDefFoundError: org.springframework.context.support.ClassPathXmlApplicationContext

What I am trying to achieve is to upload Temenos T24 Design Studio web services on Axis2.
Unfortunately, I am getting a Class not found error when uploading the service using "aar" (Axis2 archive) file.
I have already deployed Axis2 1.4.4 on IBM Websphere 9.
Note : There has been certain conflicts while deploying Axis2 application on IBM websphere JAX-WS, which I have used this guide to resolve them;
https://www-01.ibm.com/support/docview.wss?uid=swg21315686
Below is the error I am getting;
=================================
This Web axisService has deployment faults
Error: java.lang.NoClassDefFoundError: org.springframework.context.support.ClassPathXmlApplicationContext at com.temenos.services.designstudioinstaller.DesignStudioInstallerServiceSpringContext.loadServiceContext(DesignStudioInstallerServiceSpringContext.java:27)
You have to remove the following jar files from the t24lib directory:
t24-EB_ResourceProviderService-ejb.jar
t24-EB_ResourceProviderService-ProxyAdaptor.jar
t24-EB_ResourceProviderService-jws.aar
t24-EB_ResourceProviderService-provider.jar
t24-EB_ResourceProviderService-tafj-jws.aar
t24-EB_ResourceProviderService-tafj-provider.jar
For any service component such as EB_ResourceProviderService, only the below jars must be present within the t24lib directory:
EB_ResourceProviderService.jar
t24-EB_ResourceProviderService-Data.jar
t24-EB_ResourceProviderService-t24service.jar
Restart the application server after removing them and the axis2 should deploy successfully.
I had similar error deploying axis2.war inflated with Temenos aar files on JBoss EAP 7.1 and it was solved by removing the duplicated .jar and .aar files in t24lib:
[INFO] The t24-EB_ResourceProviderService-tafj-jws.aar service, which is not valid, caused java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext
at com.temenos.services.resourceprovider.ResourceProviderServiceSpringContext.loadServiceContext(ResourceProviderServiceSpringContext.java:27)

Springboot Strange Resource Loading Behavior

I'm working on a springboot 1.5.1 application that I'm trying to load a WSDL included in my resources directory in the wsdl directory. Depending on where my application executes I'm getting different results (command line, intellij, cloud foundry) and I can't seem to get all three to work at the same time.
I've tried several ways of locating the resource:
From prior to the migration to springboot we had this (worked in IntelliJ but not java -jar myboot.jar):
this.getClass().getResource("/wsdl/my.wsdl");
I switched it to the typically more correct version and got it to work in IntelliJ and java -jar but not Cloud Foundry:
this.getClass().getClassLoader().getResource("/wsdl/my.wsdl");
I switched it to use the Spring Resource Loader version and it worked in IntelliJ and CloudFoundry but not java -jar:
#Value("classpath:/wsdl/my.wsdl")
private Resource wsdlResource;
wsdlResource.getURL();
On the command line what I've noticed is that it seems to be thinking that BOOT-INF/classes is a JAR file (Note the ! after classes):
Caused by: javax.xml.ws.WebServiceException: Failed to access the WSDL at: jar:file:/C:/dev/redacted/build/libs/redacted.jar!/BOOT-INF/classes!/wsdl/my.wsdl. It failed with:
JAR entry BOOT-INF/classes!/wsdl/my.wsdl not found in C:\dev\redacted\build\libs\redacted.jar.
From looking at IntelliJ's URL, it's referring to the actual source folder which explains why it seems to always work.
What is causing this and how might I universally load these class path resources successfully with springboot?

404 when deploying Grails 3.1.10 war to tomcat7 or tomcat8

The closest stackoverflow question that explains my symptoms is here - How can I deploy a Grails 3.0.1 war file in Tomcat7?
I am in the process of upgrading a Grails 2.3.4 application to Grails 3.1.10 and everything is working with 'grails run-app'.
When i deploy to a war i get nothing but 404's for any url.
The war deploys without any error messages in catalina.out.
The tomcat access logs show my access attempts. (not linux problem?)
I can get to the tomcat manager, and the tomcat manager shows my app as "running" as true. (no errors)
Manager shows myapp-0.1 because the war file was myapp-0.1.war .. this is fine for now.
I am running Grails 3.1.10.
I have tried against Tomcat 7.0.55 as well as 8.0.92.
I have tried changing grails.serverUrl in application.groovy to various values. It is now:
//fix war name after get working
grails.serverUrl = "/myapp-0.1"
System.setProperty("server.contextPath","/myapp-0.1")
I have tried the above without "-0.1". (i was suprised to learn this was necessary - https://stackoverflow.com/a/23664531/104993)
I have tried changing "org.springframework.boo:spring-boot-starter-tomcat" from "compile" to "provided" in the build.gradle file.
Please let me know what I need to elaborate on. It's difficult to paste log outputs and config files. (i'm behind a firewall)
You add the following task to your build.gradle it will name the war what ever you want:
task wrapper(type:Wrapper){
war.archiveName='myWar.war'
}
Then when you deploy it should have the correct name and you can go to https://localhost:8080/myWar

Resources