Spring Boot Root Controller无法处理Tomcat WAR

时间:2016-04-04 05:23:11

标签: java tomcat spring-boot war web-deployment

我无法使这一行在我在Tomcat服务器上部署为WAR的Spring Boot应用程序上运行。

package com.incidenciasboard;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.incidenciasboard.bean.CambioIncidencia;
import com.incidenciasboard.bean.General;
import com.incidenciasboard.bean.Incidencia;
import com.incidenciasboard.dao.CambioIncidenciaDAO;
import com.incidenciasboard.dao.IncidenciaDAO;
import com.incidenciasboard.util.Ano;
import com.incidenciasboard.util.Dia;
import com.incidenciasboard.util.Log;
import com.incidenciasboard.util.Mes;
import com.incidenciasboard.util.ModelFecha;
import com.incidenciasboard.util.Semana;

@Controller
public class Stats {

    @Autowired
    private CambioIncidenciaDAO cambioDao;

    @Autowired
    private IncidenciaDAO dao;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login( Model model) {
        return "login";
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String statcas( Model model) {
        Log.l();
        return "redirect:/stats";
    }

    @RequestMapping(value = "/stats", method = RequestMethod.GET)
    public String stats( Model model) {

        Iterable<CambioIncidencia> cambios=cambioDao.findAll();
        ModelFecha m=new ModelFecha(0,12,2015);

        long total=0;
        int cant=1;
        //Promedio
        for(CambioIncidencia c: cambios){
            if(c.getDespues().equals("Open") && !c.getDespues().equals("Closed")){
                long id=c.getTicketid();
                for(CambioIncidencia cc: cambios){
                    long id2=cc.getTicketid();

                    if(id==id2 && cc.getDespues().equals("Closed")){
                        long cantDias=ModelFecha.diffDias(c.getFecha(), cc.getFecha());
                        cant++;
                        if(cantDias>0){
                            total+=cantDias;

                        }
                    }

                }
            }   
        }



        List<Ano> fechas=m.getFechas();
        //Cambios Mensuales
        //Log.log("Cerrados");
        for(CambioIncidencia i:cambios){
            for(Ano ano:fechas){
                General ga=ano.getGeneral();
                for(Mes mes:ano.getMeses()){
                    General gm=mes.getGeneral();
                    for(Semana sem:mes.getSemanas()){
                        General gs=sem.getGeneral();
                        for(Dia dia:sem.getDias()){
                            General gd=dia.getGeneral();
                            List<General> ges=new ArrayList<General>();
                            ges.add(ga);
                            ges.add(gm);
                            ges.add(gd);
                            ges.add(gs);

                            if(ModelFecha.mismoDia(dia.getFecha(), i.getFecha())){
                                if(i.getEstado().equals("Open")){
                                    for(General g:ges)g.sAbierto();
                                }else if(i.getEstado().equals("Closed")){
                                    for(General g:ges)g.sCerrado();
                                    for(General g:ges)g.setCaja(i.getPlata());
                                }else if(i.getEstado().equals("Critico")){
                                    for(General g:ges)g.sCritico();
                                }else if(i.getEstado().equals("Listo p/Entregar")){
                                    for(General g:ges)g.sLentregar();
                                }else if(i.getEstado().equals("Presupuesto Enviado")){
                                    for(General g:ges)g.sPenviado();
                                }else if(i.getEstado().equals("Esperando Repuestos")){
                                    for(General g:ges)g.sEsperando();
                                }else if(i.getEstado().equals("Cancelado")){
                                    for(General g:ges)g.sCancelado();
                                }else if(i.getEstado().equals("In Progress")){
                                    for(General g:ges)g.sProgreso();
                                }
                            }
                        }
                    }
                }
            }
        }

        General g=new General();

        for(Incidencia i:dao.findAll()){
            if(i.getEstado().equals("Open")){
                g.sAbierto();
            }else if(i.getEstado().equals("Closed")){
                g.sCerrado();
            }else if(i.getEstado().equals("Critico")){
                g.sCritico();
            }else if(i.getEstado().equals("Listo p/Entregar")){
                g.sLentregar();
            }else if(i.getEstado().equals("Presupuesto Enviado")){
                g.sPenviado();
            }else if(i.getEstado().equals("Esperando Repuestos")){
                g.sEsperando();
            }else if(i.getEstado().equals("Cancelado")){
                g.sCancelado();
            }else if(i.getEstado().equals("In Progress")){
                g.sProgreso();
            }

        }
        List<Mes> nubimedia = new ArrayList<Mes>();
        for(Ano a:fechas){
            for(Mes mm:a.getMeses()){
                nubimedia.add(mm);
            }
        }
        List<Mes> ult4=new ArrayList<Mes>();
        ult4.add(nubimedia.get(nubimedia.size()-5));
        ult4.add(nubimedia.get(nubimedia.size()-4));
        ult4.add(nubimedia.get(nubimedia.size()-3));
        ult4.add(nubimedia.get(nubimedia.size()-2));
        model.addAttribute("quarter",ult4);

        General mesactual=nubimedia.get(nubimedia.size()-1).getGeneral();
        General mesanterior=nubimedia.get(nubimedia.size()-2).getGeneral();

        General ayer=m.getAyer(fechas).getGeneral();
        General hoy=m.getHoy(fechas).getGeneral();


        model.addAttribute("hoy",hoy);
        model.addAttribute("ayer",ayer);
        model.addAttribute("mesactual",mesactual);
        model.addAttribute("mesanterior",mesanterior);
        model.addAttribute("prom",(total/cant));
        model.addAttribute("g",g);
        return "index";
    }


}

我没有其他选择将根控制器索引发送到&#34; / stats&#34;。

我正在使用&#34; / ..任何事物......&#34;有用。但&#34; /&#34;没有按&#39;吨。你看到我现在拥有的重定向,当我使用嵌入式tomcat运行spring boot时它会起作用,但是当我将它作为战争部署时则不行。

我也做了一个日志,但它甚至不打印。

@RequestMapping(value = "/", method = RequestMethod.GET)
        public String statcas( Model model) {
            Log.l();
            return "redirect:/stats";
        }

请帮忙!

编辑1:

应用它的名为Incendencia,因此在url中看起来像这样:

主机:8080 / Incidencia /

如果网址完全相同,则不会重定向到/ stats ...

要使用该应用程序,我必须将主机:8080 / Incidencia / stats

编辑2: 属性文件spring boot:

#REMOTO
spring.datasource.url = jdbc:mysql://...
spring.datasource.username = ...
spring.datasource.password = ...

spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = false
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

#jsp
spring.mvc.view.suffix: .jsp

和POM文件

<?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.incidenciasboard</groupId>
    <artifactId>incidenciasboard</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>IncidenciasBoard</name>
    <description>incidenciasboard</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</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-web</artifactId>
        </dependency>
        <dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>19.0</version>
</dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.0</version>
    </dependency>
    </dependencies>

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


</project>

1 个答案:

答案 0 :(得分:-5)

我不确定以下内容是否满足您的需求,但您可以将其转换为JAR文件并运行,而不是将其作为WAR文件。这将有效