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
New contributor
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
New contributor
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 helppublic class Application extends SpringBootServletInitializer
– XMCK
2 days ago
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
New contributor
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
New contributor
New contributor
edited yesterday
Joakim Erdfelt
31.9k45594
31.9k45594
New contributor
asked 2 days ago
XMCK
11
11
New contributor
New contributor
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 helppublic class Application extends SpringBootServletInitializer
– XMCK
2 days ago
add a comment |
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 helppublic 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
add a comment |
active
oldest
votes
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.
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.
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
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
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
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
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
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