Start Boot Spring Rest (without the embedded server) on running jetty
up vote
-1
down vote
favorite
I want to ask a question about building a REST API on spring boot. I coded an application and now it is possible to make the api calls over the embedded server. But I don't want to have two different servers. I want to run the application on the jetty server which is already running.
here is the pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xmck</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>This is a test application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>local-repository</id>
<url>file:///$project.basedir/local-repository/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
here is the src/main/java/test/Application.java file to run the Application
package test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application
public static void main(String args)
SpringApplication.run(Application.class, args);
and here is the file src/main/java/test/MyRequestController.java
package test;
import java.io.IOException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyRequestController
@RequestMapping(value = "/test", method = RequestMethod.GET)
@CrossOrigin
public String getContent() throws IOException
return "This is a string";
and the src/main/resources/application.properties file
server.port=8090
these are all the files and code I have
what do I have to change for running a rest api like this on a running jetty server
java spring spring-boot jetty spring-restcontroller
add a comment |
up vote
-1
down vote
favorite
I want to ask a question about building a REST API on spring boot. I coded an application and now it is possible to make the api calls over the embedded server. But I don't want to have two different servers. I want to run the application on the jetty server which is already running.
here is the pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xmck</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>This is a test application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>local-repository</id>
<url>file:///$project.basedir/local-repository/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
here is the src/main/java/test/Application.java file to run the Application
package test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application
public static void main(String args)
SpringApplication.run(Application.class, args);
and here is the file src/main/java/test/MyRequestController.java
package test;
import java.io.IOException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyRequestController
@RequestMapping(value = "/test", method = RequestMethod.GET)
@CrossOrigin
public String getContent() throws IOException
return "This is a string";
and the src/main/resources/application.properties file
server.port=8090
these are all the files and code I have
what do I have to change for running a rest api like this on a running jetty server
java spring spring-boot jetty spring-restcontroller
Let me know the exact error.
– GauravRai1512
Nov 10 at 14:19
Have you used @componentscan with main springboot class?
– GauravRai1512
Nov 10 at 14:20
You need to build your application as a war file and deploy it to Jetty. The Spring Boot documentation describes how to do that.
– Andy Wilkinson
Nov 10 at 14:39
I edited my post now with the full code of my Application.. When I start it like this the application is giving me the String "This is a string" for the page localhost:8090/test . What do I have to do to create a webapp for a running jetty server? I tried it like on the link but it did not give the result "This is a string"
– XMCK
Nov 10 at 20:38
now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your helppublic class Application extends SpringBootServletInitializer
– XMCK
Nov 10 at 23:43
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I want to ask a question about building a REST API on spring boot. I coded an application and now it is possible to make the api calls over the embedded server. But I don't want to have two different servers. I want to run the application on the jetty server which is already running.
here is the pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xmck</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>This is a test application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>local-repository</id>
<url>file:///$project.basedir/local-repository/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
here is the src/main/java/test/Application.java file to run the Application
package test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application
public static void main(String args)
SpringApplication.run(Application.class, args);
and here is the file src/main/java/test/MyRequestController.java
package test;
import java.io.IOException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyRequestController
@RequestMapping(value = "/test", method = RequestMethod.GET)
@CrossOrigin
public String getContent() throws IOException
return "This is a string";
and the src/main/resources/application.properties file
server.port=8090
these are all the files and code I have
what do I have to change for running a rest api like this on a running jetty server
java spring spring-boot jetty spring-restcontroller
I want to ask a question about building a REST API on spring boot. I coded an application and now it is possible to make the api calls over the embedded server. But I don't want to have two different servers. I want to run the application on the jetty server which is already running.
here is the pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xmck</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>This is a test application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>local-repository</id>
<url>file:///$project.basedir/local-repository/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
here is the src/main/java/test/Application.java file to run the Application
package test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application
public static void main(String args)
SpringApplication.run(Application.class, args);
and here is the file src/main/java/test/MyRequestController.java
package test;
import java.io.IOException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyRequestController
@RequestMapping(value = "/test", method = RequestMethod.GET)
@CrossOrigin
public String getContent() throws IOException
return "This is a string";
and the src/main/resources/application.properties file
server.port=8090
these are all the files and code I have
what do I have to change for running a rest api like this on a running jetty server
java spring spring-boot jetty spring-restcontroller
java spring spring-boot jetty spring-restcontroller
edited Nov 11 at 14:41
Joakim Erdfelt
32.2k45695
32.2k45695
asked Nov 10 at 13:10
XMCK
11
11
Let me know the exact error.
– GauravRai1512
Nov 10 at 14:19
Have you used @componentscan with main springboot class?
– GauravRai1512
Nov 10 at 14:20
You need to build your application as a war file and deploy it to Jetty. The Spring Boot documentation describes how to do that.
– Andy Wilkinson
Nov 10 at 14:39
I edited my post now with the full code of my Application.. When I start it like this the application is giving me the String "This is a string" for the page localhost:8090/test . What do I have to do to create a webapp for a running jetty server? I tried it like on the link but it did not give the result "This is a string"
– XMCK
Nov 10 at 20:38
now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your helppublic class Application extends SpringBootServletInitializer
– XMCK
Nov 10 at 23:43
add a comment |
Let me know the exact error.
– GauravRai1512
Nov 10 at 14:19
Have you used @componentscan with main springboot class?
– GauravRai1512
Nov 10 at 14:20
You need to build your application as a war file and deploy it to Jetty. The Spring Boot documentation describes how to do that.
– Andy Wilkinson
Nov 10 at 14:39
I edited my post now with the full code of my Application.. When I start it like this the application is giving me the String "This is a string" for the page localhost:8090/test . What do I have to do to create a webapp for a running jetty server? I tried it like on the link but it did not give the result "This is a string"
– XMCK
Nov 10 at 20:38
now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your helppublic class Application extends SpringBootServletInitializer
– XMCK
Nov 10 at 23:43
Let me know the exact error.
– GauravRai1512
Nov 10 at 14:19
Let me know the exact error.
– GauravRai1512
Nov 10 at 14:19
Have you used @componentscan with main springboot class?
– GauravRai1512
Nov 10 at 14:20
Have you used @componentscan with main springboot class?
– GauravRai1512
Nov 10 at 14:20
You need to build your application as a war file and deploy it to Jetty. The Spring Boot documentation describes how to do that.
– Andy Wilkinson
Nov 10 at 14:39
You need to build your application as a war file and deploy it to Jetty. The Spring Boot documentation describes how to do that.
– Andy Wilkinson
Nov 10 at 14:39
I edited my post now with the full code of my Application.. When I start it like this the application is giving me the String "This is a string" for the page localhost:8090/test . What do I have to do to create a webapp for a running jetty server? I tried it like on the link but it did not give the result "This is a string"
– XMCK
Nov 10 at 20:38
I edited my post now with the full code of my Application.. When I start it like this the application is giving me the String "This is a string" for the page localhost:8090/test . What do I have to do to create a webapp for a running jetty server? I tried it like on the link but it did not give the result "This is a string"
– XMCK
Nov 10 at 20:38
now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help
public class Application extends SpringBootServletInitializer
– XMCK
Nov 10 at 23:43
now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help
public class Application extends SpringBootServletInitializer
– XMCK
Nov 10 at 23:43
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239273%2fstart-boot-spring-rest-without-the-embedded-server-on-running-jetty%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Let me know the exact error.
– GauravRai1512
Nov 10 at 14:19
Have you used @componentscan with main springboot class?
– GauravRai1512
Nov 10 at 14:20
You need to build your application as a war file and deploy it to Jetty. The Spring Boot documentation describes how to do that.
– Andy Wilkinson
Nov 10 at 14:39
I edited my post now with the full code of my Application.. When I start it like this the application is giving me the String "This is a string" for the page localhost:8090/test . What do I have to do to create a webapp for a running jetty server? I tried it like on the link but it did not give the result "This is a string"
– XMCK
Nov 10 at 20:38
now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help
public class Application extends SpringBootServletInitializer
– XMCK
Nov 10 at 23:43