Error 404 Spring boot Ubuntu

Asked

Viewed 173 times

1

Says Guys, I’m trying to create a Restful application with spring boot here in Ubuntu, however, when I run the application "Run as java application", the server goes up but it seems to me that it does not deploy the application, because when I try to access the url gives error 404.

Detail: In windows works.

Single class:

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class DemoApplication {

  @RequestMapping("/")
  String home() {
    return "Hello World!";
  } 

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  } 
}

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.4.3.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>
    </properties>   
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

HERE’S THE LOG

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-02-07 21:13:27.814  INFO 3975 --- [           main] com.example.DemoApplication              : Starting DemoApplication on meu pc
2017-02-07 21:13:27.817  INFO 3975 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-02-07 21:13:27.858  INFO 3975 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64cd705f: startup date [Tue Feb 07 21:13:27 BRST 2017]; root of context hierarchy
2017-02-07 21:13:28.894  INFO 3975 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-02-07 21:13:28.904  INFO 3975 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-02-07 21:13:28.905  INFO 3975 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-02-07 21:13:28.974  INFO 3975 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-02-07 21:13:28.975  INFO 3975 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1119 ms
2017-02-07 21:13:29.011  INFO 3975 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-02-07 21:13:29.226  INFO 3975 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-02-07 21:13:29.256  INFO 3975 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-02-07 21:13:29.262  INFO 3975 --- [           main] com.example.DemoApplication              : Started DemoApplication in 1.881 seconds (JVM running for 2.131)

Url’s I tried to access:
localhost:8080
localhost:8080/demo
localhost:8080/demo/Demoapplication

Thank you in advance.

  • Try to change the port.

  • Speak Lucas blza? thanks for the feedback, I changed the door here and the error still persists :(

  • It is strange because it does not signal any kind of error. The log is complete or is only a part?

  • Yes, it does not signal anything, this is the complete log :(, and the strange thing is that windows works...

  • Try accessing with your machine’s IP instead of using localhost.

  • tried now and unsuccessfully. (, I searched the net and also could not find the solution to this.

  • Which browser you are using?

  • tested on Chrome and firefox

Show 4 more comments

4 answers

0

Solved!

I went to the site spring.io and created a project with the following settings: -Web -Web Services -JPA -Spring data.

worked smoothly. thanks a lot guys.

0

You may not have permission in your directory. If you do not have it, try running the following command:

sudo chmod +x "seu diretorio"

Updated Also try to access as follows in Firefox:

0.0.0.0:80

  • I performed the two steps, and unsuccessfully :(

0

I could try to force Spring to scan the class:

@ComponentScan(basePackageClasses = DemoApplication.class)

Another thing, the note @Springbootapplication is in some other application class? I believe it should be in Demoapplication.

  • Oops, thanks for the feedback, so this application is only for testing and has only this Demoapplication class, I will test the way you said.

  • I tested here, and unsuccessfully :(

0

I created a project using this pom and it worked:


<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>teste</groupId>
  <artifactId>teste</artifactId>
  <version>0.0.1-SNAPSHOT</version>

<name>demo</name> <Description>Demo project for Spring Boot</Description>

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.BUILD-SNAPSHOT</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </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-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>

The only difference is that I used version 1.4.0 of spring-boot-Starter-Parent.

Another detail, in the pom you put I did not see the opening tag "dependencies".

  • opa, thanks for the feedback, the pom is with the tag dependencies open here yes, just did not come out in the code there, I tried this way and also did not give, I solved the problem going in the official site of spring.io, and creating a project with Web + JPA + Webservices + Spring Data, the site created for me and worked here, thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.