Error 404 Spring boot ubuntu

1
I'm trying to create a RESTful application with spring boot here in Ubuntu, but 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 404 error.

Detail: No 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 that I tried to access:
localhost: 8080
localhost: 8080 / demo
localhost: 8080 / demo / DemoApplication

Thank you in advance.

    
asked by anonymous 08.02.2017 / 00:42

4 answers

0

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

sudo chmod +x "seu diretorio"

Updated Also try to access as follows in Firefox:

0.0.0.0:80

    
08.02.2017 / 01:09
0

I could try to force Spring to scan the class:

@ComponentScan(basePackageClasses = DemoApplication.class)

Another thing, the @SpringBootApplication annotation is in some other class of the application? I think she should be in DemoApplication.

    
08.02.2017 / 02:18
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 that you put I did not see the opening of the "dependencies" tag.

    
09.02.2017 / 03:04
0

Solved!

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

It worked without problems. Thanks guys.

    
09.02.2017 / 22:50