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










share|improve this question























  • 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















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










share|improve this question























  • 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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 help public class Application extends SpringBootServletInitializer
    – XMCK
    Nov 10 at 23:43

















  • 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
















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


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo