我正在尝试使用gradle,spring boot和spring mvc以最简单的视图解析器和html制作"hello world"应用程序.
我从thymeleaf spring boot示例开始,我只想删除thymeleaf,使用纯html和InternalResourceViewResolver创建一个更简单的mvc应用程序.我有一个greeting.html我想要服务,它位于src/main/webapp/WEB-INF.当我运行应用程序时,我得到了
No mapping found for HTTP request with URI [/WEB-INF/greeting.html] in DispatcherServlet with name 'dispatcherServlet'
Run Code Online (Sandbox Code Playgroud)
这是一个常见的错误,网上有很多答案,但似乎没有任何帮助.
这是我的Application.java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的GreetingController.java
@Controller
public class GreetingController {
@RequestMapping("/greeting")
public String greeting() {
return "greeting";
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的MvcConfiguration.java
@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".html");
return resolver;
}
}
Run Code Online (Sandbox Code Playgroud)
我用它来运行它 …
我想在我的第一个SpringBoot应用程序中启动我的登录页面:
主类
@SpringBootApplication
public class MainGate extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainGate.class);
}
public static void main(String... args) {
System.out.println("Booting .. ");
SpringApplication.run(MainGate.class, args) ;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Gradle文件
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
maven {
url "http://masked_domain/repository/external-proxy-group/"
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.arun'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
task fatJar(type: Jar) …Run Code Online (Sandbox Code Playgroud)