Gradle - нет карт для GET /WEB-INF/jsp/welcome.jsp " - PullRequest
0 голосов
/ 12 февраля 2019

Я пытаюсь использовать spring-boot и gradle для создания простого приложения CRUD в качестве PoC.В этот момент я получаю эту ошибку, когда пытаюсь загрузить передний веб-сайт -

2019-02-11 14:54:48.915 WARN 5704 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound : No mapping for GET /WEB-INF/jsp/welcome.jsp

Я использую пружинную загрузку и gradle, указав в классе контроллера иСвойства приложения и сценарий сборки gradle, но все же я получаю этот оператор отладки, когда захожу в мой welcome.jsp и теперь соответствующую ошибку 404.

Я уже просмотрел много учебных пособий, но многие из них в maven.На данный момент я знаю, что мне нужно указать путь в контроллере и указать ресурсы в свойствах и сценариях сборки.Я даже пытался создать определенную конфигурацию mvcconfiguration, но я не думаю, что она мне нужна.

build.gradle

buildscript {
    ext {
        springBootVersion = '2.1.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }} 
  apply plugin: 'eclipse' 
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.bill'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
}

ext {
    set('springCloudServicesVersion', '2.1.0.RELEASE')
    set('springCloudVersion', 'Greenwich.RELEASE')
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-actuator'

    /*implementation 'io.pivotal.spring.cloud:spring-cloud-services-starter-config-client'
    /*implementation 'io.pivotal.spring.cloud:spring-cloud-services-starter-service-registry'
    implementation 'org.springframework.cloud:spring-cloud-starter'
    /*implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-ribbon'
    */
  runtimeOnly 'mysql:mysql-connector-java'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencyManagement {
    imports {
        mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:${springCloudServicesVersion}"
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

application.properties

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/mh1
spring.datasource.username=root
spring.datasource.password=root

MainController.java

package com.javainuse;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.javainuse.BankAccountApplication;
import com.javainuse.User;
import com.javainuse.UserDAO;
import com.javainuse.UserForm;

@Controller
public class MainController {
    @Autowired
    UserDAO userDAO;


    @RequestMapping("/welcome")
    public ModelAndView viewHome() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("welcome");
        return modelAndView;


    } 


    @RequestMapping("/users")
    public String viewUsers(Model model) {
        List<User> list = UserDAO.getUsers();

        model.addAttribute("users", list);

        return "usersPage";
    }

    @RequestMapping("/registerSuccessful")
    public String viewRegisterSuccessful() {
        return "registerSuccessfulPage";
    }

    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public String viewRegister(Model model) {
        UserForm form = new UserForm();

        model.addAttribute("userForm", form);

        return "registerPage";
    }

    public String saveRegister( Model model, //
             @ModelAttribute("userForm") @Validated UserForm userForm, //
             BindingResult result, //
             final RedirectAttributes redirectAttributes) {

          // Validate result
          if (result.hasErrors()) {
             return "registerPage";
          }
          User newUser= null;
          try {
             newUser = userDAO.createUser(userForm);
          }
          // Other error!!
          catch (Exception e) {
             model.addAttribute("errorMessage", "Error: " + e.getMessage());
             return "registerPage";
          }

          redirectAttributes.addFlashAttribute("newUser", newUser);

          return "redirect:/registerSuccessful";
       }
}

MvcConfiguration.java

package com.javainuse;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@ComponentScan(basePackages="...package name...")
@EnableWebMvc

public class MvcConfiguration extends WebMvcConfigurerAdapter{

  @Bean
  public InternalResourceViewResolver viewResolver() {

     InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
     viewResolver.setPrefix("WEB-INF/jsp/");
     viewResolver.setSuffix(".jsp");

   return viewResolver;
}
}

2019-02-11 14: 54: 48.915 WARN 5704 --- [nio-8080-exec-3] osweb.servlet.PageNotFound: нет сопоставления для GET /WEB-INF/jsp/welcome.jsp

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...