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









New contributor




XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Let me know the exact error.
    – GauravRai1512
    2 days ago










  • Have you used @componentscan with main springboot class?
    – GauravRai1512
    2 days ago










  • 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
    2 days ago












  • 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
    2 days ago










  • now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help public class Application extends SpringBootServletInitializer
    – XMCK
    2 days ago

















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









New contributor




XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Let me know the exact error.
    – GauravRai1512
    2 days ago










  • Have you used @componentscan with main springboot class?
    – GauravRai1512
    2 days ago










  • 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
    2 days ago












  • 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
    2 days ago










  • now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help public class Application extends SpringBootServletInitializer
    – XMCK
    2 days ago















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









New contributor




XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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









New contributor




XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Joakim Erdfelt

31.9k45594




31.9k45594






New contributor




XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









XMCK

11




11




New contributor




XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






XMCK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Let me know the exact error.
    – GauravRai1512
    2 days ago










  • Have you used @componentscan with main springboot class?
    – GauravRai1512
    2 days ago










  • 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
    2 days ago












  • 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
    2 days ago










  • now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help public class Application extends SpringBootServletInitializer
    – XMCK
    2 days ago




















  • Let me know the exact error.
    – GauravRai1512
    2 days ago










  • Have you used @componentscan with main springboot class?
    – GauravRai1512
    2 days ago










  • 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
    2 days ago












  • 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
    2 days ago










  • now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help public class Application extends SpringBootServletInitializer
    – XMCK
    2 days ago


















Let me know the exact error.
– GauravRai1512
2 days ago




Let me know the exact error.
– GauravRai1512
2 days ago












Have you used @componentscan with main springboot class?
– GauravRai1512
2 days ago




Have you used @componentscan with main springboot class?
– GauravRai1512
2 days ago












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
2 days ago






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
2 days ago














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
2 days ago




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
2 days ago












now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help public class Application extends SpringBootServletInitializer
– XMCK
2 days ago






now it works. the mistake was that i did not extend the SpringBootServletInitializer thanks for your help public class Application extends SpringBootServletInitializer
– XMCK
2 days ago



















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
});


}
});






XMCK is a new contributor. Be nice, and check out our Code of Conduct.










 

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





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








XMCK is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















XMCK is a new contributor. Be nice, and check out our Code of Conduct.













XMCK is a new contributor. Be nice, and check out our Code of Conduct.












XMCK is a new contributor. Be nice, and check out our Code of Conduct.















 


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




















































































Popular posts from this blog

Bressuire

Vorschmack

Quarantine