2

if i call the default url for my tomcat server, i will see an error 404. The program is running without any problems, but perhaps the restcontroller is disabled (i don't known, normally not). There are no erros in the log. The start page is a html-format. I set the default path (see below).

Im using Spring Boot and tomcat7.

The requested resource (/dashboard/) is not available.

Spring Boot path src\main\resources\templates\index.html

Index.html path in war: ..\tomcat7\webapps\dashboard\WEB-INF\classes\templates\index.html

Main

@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.###.dashboard")
@EnableJpaRepositories
@EntityScan(basePackages = "com.###.dashboard.domain")
public class Dashboard extends SpringBootServletInitializer  {

    public static void main(String[] args) {
        SpringApplication.run(new Object[] {Dashboard.class, DashboardController.class}, args);    
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Dashboard.class);
    }


}

RestController

@RestController
public class DashboardController {


    /**
     *...
     */
    @RequestMapping("/")
    public String setPage(Model model) {

        // ...

        return "index";
    }
}

pom

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.###.dashboard</groupId>
  <artifactId>Dashboard</artifactId>
  <packaging>war</packaging>
  <version>1.0</version>
  <name>Dashboard</name>
  <url>http://maven.apache.org</url>

     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.8.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mobile</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>


        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>   

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>       

    </dependencies>

    <properties>
        <start-class>com.###.dashboard.main.Dashboard</start-class>
    </properties>

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


        </plugins>
    </build>

</project>

tomcat7 server

2014-12-05 13:31:46.836  INFO 28052 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],param
s=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.###.dashboard.domain.DashboardController.setPage(org.springframework.ui.Model)

Thank you

blauni
  • 41
  • 1
  • 2
  • 6
  • What happens when you make a request to "/" ? – Pumpkin Dec 05 '14 at 12:38
  • / = white page, /dashboard/ = The requested resource (/dashboard/) is not available. – blauni Dec 05 '14 at 12:39
  • Maybe not the problem but it sounds like you just want `@Controller` and not `@RestController`. RestController is for handling serialized data directly rather than going through the View resolver – Matt Whipple Dec 05 '14 at 12:40
  • I tried @Controller yesterday, same problem – blauni Dec 05 '14 at 12:41
  • I had the same problem. Turned out I forgot to add the `spring-boot-starter-thymeleaf` dependency to the pom.xml file, but I can see you did this... Have you tried to go to the pom.xml file and run `mvn clean install package`? The downloaded dependencies might be unsynchronized with the pom file. – ldavid Dec 21 '14 at 01:59
  • I got the problem. I updated the tomcat version and now its anything okay... – blauni Jan 05 '15 at 13:57

5 Answers5

0

try to put templates in src/main/resources/templates (it's another default path for spring boot)

it works for me and resources/templates sounds better than resources/resources :)

Cuzz
  • 428
  • 2
  • 4
  • 20
  • Im sorry, i use resources/templates. My fault. Problem is still there. – blauni Dec 05 '14 at 12:47
  • your comment to another answer was: "The homepage is there. "src\main\resources\templates" If i start the project in eclise, i dont get any errors and he finds the page." a u sure u put war as root to tomcat, cause another way path, for example if u put it to webapps/folder, will be localhost:8080/folder – Cuzz Dec 05 '14 at 13:00
  • Im sure, i put the war as root – blauni Dec 05 '14 at 13:06
0

Try annotating your controller as @Controller and give '/dashboard' default request mapping to the controller so that the dashboard controller can answer to the requests with uri starting as '/dashboard'

@Controller
@RequestMapping("/dashboard")
public class DashboardController

Use debug points to see whether the request has fallen thourgh your controller pipeline, white page might be related to an empty template

Pumpkin
  • 1,993
  • 3
  • 26
  • 32
0

It means your spring container is not able to find the default page. Just add your home page into the src or make a proper redirection of the home page. For the testing purpose you can use the complete mapping on the web where you have put the home page.

Mike Clark
  • 1,860
  • 14
  • 21
  • The homepage is there. "src\main\resources\templates" If i start the project in eclise, i dont get any errors and he finds the page. – blauni Dec 05 '14 at 12:53
  • I thing you need to add your page in WEB-INF or http://stackoverflow.com/questions/2511301/setting-the-default-jsp-view-with-spring-mvc – Mike Clark Dec 05 '14 at 12:58
  • Normally i thought that i dont need any xml files. http://spring.io/guides/gs/convert-jar-to-war-maven/ – blauni Dec 05 '14 at 13:11
0

With below changes it worked.

I commented out spring-boot-starter-thymeleaf because it was asking to put some templates to /templates folder. After that i added @ResponseBody to RequestMapping to return String.

    @RequestMapping("/")
    public @ResponseBody String setPage(Model model) {
        return "index";
    }

So maybe you have problem with spring-boot-starter-thymeleaf

Note: I started the tomcat using spring-boot-maven-plugin plugin in your pom with command line mvn spring-boot:run

  • Thank you, but it still dont work. I create a war for an embedded tomcat. It loads the classes but there is still a 404 error. – blauni Dec 08 '14 at 08:06
  • Writing `@ResponseBody` before `String` makes the controller to output the word "index" as answer to a browser request, instead of outputting the content of the view resources/templates/index.html. – ldavid Dec 21 '14 at 01:24
-2

Here's quite so many get errors while working with Tomcat7 without MAVEN like adding hibernate validator and hibernate dependencies in spring notice one thing update your eclipse. And shift to Tomcat 8 it is set up with API-3.0 so every hibernate component works with it. Even some error doubts just free to ask me.

@navajavadevolper

Akif
  • 7,098
  • 7
  • 27
  • 53