Unable to run localhost in Spring Boot application (Tomcat server)
Unable to run localhost in Spring Boot application (Tomcat server)
I've been learning Spring using the following tutorials: https://www.youtube.com/playlist?list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
I have created a Maven project and tried to run the Spring Boot application while referring to these videos:
https://www.youtube.com/watch?v=E7_a-kB46LU&index=9&list=PLqq-6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x
I tried to run my Spring application on Tomcat server but the localhost isn't working. (Port 8080)
My pom.xml looks like this:
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>course-api-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Course API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
CourseApiApp.java :
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp
public static void main(String args)
SpringApplication.run(CourseApiApp.class, args);
According to the video localhost should display Whitelist error on running the application, but it doesn't run at all.
Any help would be appreciated, thanks!
@pvpkiran Not running as in not executing anything on the browser saying "Localhost refused to connect". Yes there are errors shown in the STS but Spring starts without any problems. As for the plugin, I am unaware of it since I've just started learning this framework. Please check out the video link if it could be of use to you.
– Navneet Joshi
Jul 11 '17 at 9:29
If you start your app, what messages appear in the console view?
– Martin Lippert
Jul 11 '17 at 13:26
@MartinLippert Sometimes, I get this Error: Could not find or load main class io.javabrains.springbootstarter.CourseApiApp .After somehow solving this error, Console doesn't show any errors but doesn't show any message related to "Tomcat started running on Port 8080" sorts. Also check out the video I'm referring to.
– Navneet Joshi
Jul 12 '17 at 7:38
6 Answers
6
I would suggest that you start your project from beginning. To create a valid spring-boot
project you have a very good web based generator for spring-boot
starter applications.
spring-boot
spring-boot
For a web application with an embedded tomcat you should use web
project.
web
Using STS
you can create the same by choosing new -> spring starter project
.
STS
new -> spring starter project
A wizard will appear and you can choose your project informations:
And then in the second step you dependencies:
After generating your project your pom.xml
should look like that:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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>
</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>
</project>
Your application should start normally and tomcat listens on localhost:8080
.
localhost:8080
Hi @Patrick , Thanks for your answer. I tried your method but localhost still doesn't run. I downloaded Eclipse instead of Spring tool suite, made a fresh project and still got the same problems. Could you suggest something else? Thanks.
– Navneet Joshi
Jul 12 '17 at 7:41
@NavneetJoshi that is very strange. Can you please provide any more informations, exceptions and so on.
– Patrick
Jul 12 '17 at 7:57
On running the program, STS alerts me that the project has errors (doesn't show what errors they are) but My CourseApiApp.java runs fine. But it fails to show any message related to "Tomcat started running...." and localhost:8080 shows "localhost refused to connect". I've tried adding port info to application.properties file but it leads to another error that previously existed, ie. "Could not find or load main class io.javabrains.springbootstarter.CourseApiApp". Please check out the video I was referring to if that helps.
– Navneet Joshi
Jul 12 '17 at 8:14
How do I send you a screenshot of the Console?
– Navneet Joshi
Jul 12 '17 at 8:16
It could be possible that STS by default uses Tomcat version 7 and if you happen to use version 8, then would need to specify the same in pom.xml
<properties>
<tomcat.version>8.0.47</tomcat.version>
</properties>
You should try to run spring-boot as sudo
sudo mvn spring-boot:run
I also faced the same issue. Try creating Spring Boot apprlication by choosing Spring Boot starter project in STS.
Right click on STS->New->Spring Starter Project->Give name and click on Next->Choose Web and tick mark on Web and search for Dev Tools and tick mark Dev Tools and click on Finish
Now click on the project and Run as Spring Boot Application.
In application.properties put server.port=8080
I faced the similar issue. I too was following the JavaBrains SpringBoot example. This is what I did:
I created a fresh spring boot project using STS tool and included the same code as provided by you and it worked!
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy
firstly. what do you meant by not running. Do you see any messages or exception. If so put stack trace. Next is in your pom, do you have spring boot maven plugin or not?
– pvpkiran
Jul 11 '17 at 9:23