I'm trying to deploy a Spring Boot app to AWS Beanstalk. Originally I had the app compile into a jar, so I had a main class with #SpringBootApplication annotation. Locally, everything works fine.
I changed the app so that it creates a war file by adding <packaging>war</packaging> to my pom.xml. I also followed this post:
Deploy Spring Boot app to AWS Beanstalk to create the initalizer:
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class MyBootWebApp extends SpringBootServletInitializer {
#Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyBootWebApp.class);
}
}
Now when I deploy the app to Beanstalk it doesn't do anything, I get 404 error when I navigate to the root url. What else am I missing? I checked the server logs and there are no errors or failures, so I'm not sure where else to look.
Related
I built a Spring Boot Rest API and want it to run in a Tomcat container on a Linux server.
I have a server on digitalocean running on Ubuntu 20.4
I installed tomcat as described in this article and it is running
I build a very small Spring Boot Application with only one endpoint, which I want to build and deploy on the tomcat server. You can see the build.gradle file here in my github repository: spring-boot-example
Here are some Code Snippets:
#RestController
public class ExampleController {
#GetMapping(value = "/hello-world")
public ResponseEntity<String> helloWorld() {
return ResponseEntity.ok("Hello world");
}
}
#SpringBootApplication
public class ExampleApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ExampleApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class);
}
}
This is basically the whole app
Steps taken:
building the war file with './gradlew war' or './gradlew bootWar' locally on my machine (I tried both, i don't know if it makes any difference, but I had the issue with both of them)
Opening the tomcat manager remotely on http://'host':8080/manager/html
Deploying the .war file manually and waiting until it's deployed:
As you can see, it is up and running:
Now I open the following URL: http://host:8080/spring-boot-example/hello-world, where I expect to see the message Hello world, as defined in the Controller
But all I can see is this
Did I miss something? It says at the end or is not willing to disclose that one exists, do I have to do something with that endpoint to make it available to the public? Or did I upload the app incorrectly?
I am using Jersey 2.x and integrated Swagger into my application.
API Doc for Swagger Integration with Jersey : Swagger-Core-Jersey-2.X-Project-Setup
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
Running on Local Machine + Tomcat :
Swagger Endpoint running fine on my local machine if deployed on Tomcat. Please have a look on the screenshot below:
Running on WebSphere (WAS):
If I deploy the same war file on WAS, I am getting 404 Not Found error for GET swagger.json endpoint.
However other CRUD operation APIs are working perfectly fine. I also able to see LOG statement printed in Bootstrap class which means swagger intilized but endpoint is not working as expected.
Below is my Bootstrap class which I have initialized in web.xml
public class Bootstrap extends HttpServlet {
private static Logger LOGGER = LogManager.getLogger(Bootstrap.class);
#Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println("Inside Bootstrap........");
BeanConfig beanConfig = new BeanConfig();
beanConfig.setTitle("Rest APIs Documentation");
beanConfig.setContact("you#your-company.com");
beanConfig.setVersion("1.0.0");
beanConfig.setSchemes(new String[]{"http"});
//beanConfig.setHost("localhost:9060");
//beanConfig.setBasePath("/mdm-swagger/api");
beanConfig.setResourcePackage("com.api.rs");
beanConfig.setPrettyPrint(true);
beanConfig.setScan(true);
LOGGER.info("Inside Bootstrap finish........");
}
}
I have commented host and basepath as I want to use swagger for documentation purpose not like any client.
Could you please suggest possible solution why I am getting 404 Not Found error?
Thanks a lot.
I have application written in Spring Boot 2 and REST API. When I run this app on embeded Tomcat server via bootRun gradle task everything is fine.
The problem is that when this application is deployed on standalone Tomcat 8.5 server response is truncated to 8kB. Why is that?
My REST controller:
#RestController
public class ApiController {
public ResponseEntity<Mono<ResultData>> get(String param) {
// generating data
return ResponseEntity.ok(Mono.just(ResultData.builder()
.data(data)
.build()));
}
}
Solved. I have not extended SpringBootServletInitializer (https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html) - when you would like to run Spring Boot app as deployable war you have to do this.
I'm trying to connect a Spring Boot app running locally/not in Google app engine when deployed to my Google DataStore. I am using Objectify and Google Remote API as my understanding is that Objectify will only work if deployed in App engine(?). The problem is that the Google Remote API is throwing 404 when I try and communicate with the DataStore. I think I might have my config wrong in spring boot as the instructions on the google docs talk about setting up config in web.xml which I don't use on my JAR based spring boot app. I have created a SpringBootServletInitializer class to try and register the servlet (code at the bottom). I'm coming at this from an AWS perspective and so far I've found Google cloud to be a nightmare! Connecting to DynamoDB is so much simpler and I feel I must be missing something!
import com.google.apphosting.utils.remoteapi.RemoteApiServlet;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Thomas on 01/07/2017.
*/
#Configuration
public class GoogleRemoteApiConfig extends SpringBootServletInitializer {
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(GoogleRemoteApiConfig.class, "/remote_api");
}
#Bean
public ServletRegistrationBean remoteApiRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new RemoteApiServlet(), "/remote_api");
Map<String,String> params = new HashMap<String,String>();
registration.setInitParameters(params);
registration.setLoadOnStartup(1);
registration.setUrlMappings(Arrays.asList("/remote_api"));
registration.setName("RemoteApiServlet");
return registration;
}
}
I'd fundamentally misunderstood how the remote-api worked, and didn't realise I needed an app running in app engine to proxy the requests on to Google DataStore. I'm still confused that there is no simple way to access DataStore from Java but this approach is at least working!
I am trying to load the external properties file in spring boot with tomcat it is working as expected while putting it in lib folder but I am not able to load with weblogic server though I put application.properties file in lib folder.
Code snippet :
public class ApplicationFilesInitializer extends SpringBootServletInitializer implements WebApplicationInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class).properties(getProperties());
}
static Properties getProperties() {
Properties props = new Properties();
props.put("spring.config.location","classpath:{appname}-application.properties");
return props;
}
}
So Below is the link to load external properties file.
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
The code which you share will work in tomcat as under lib folder is the actual classpath so it will load while server start up, but it will not work with weblogic as weblogic classpath is user domain folder and not the lib folder.
Can you try to put application.properties file in user domain folder and it should work.
Find your user domain path in weblogic and put app. files there.
Below is the code you can find your weblogic user domain path/classpath :
String appDomianPath= System.getProperty("user.dir");
System.out.println(appDomianPath);