我试图创建一个spring boot starter项目。当我试着运行这个时,我遇到了这个错误。
白标签错误页面
此应用程序没有 /error的显式映射,因此您将此视为后备。
Fri Dec29 14:16:46IST 2017有一个意外的错误(type=未找到,status=404)。/
我将jsp文件添加到src/web-inf/views中/
已添加
Springmvc。看法前缀=/WEB-INF/views/spring。mvc。看法后缀=。jsp spring。mvc。静态路径模式=/资源/**
应用程序。属性文件。
创建了另一个控制器:
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "index";
}
@PostMapping("/hello")
public String sayHello(@RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "hello";
}
}
但当我试着运行时,同样的错误发生了。
经过大量研究,我发现我应该添加WebMVCConfigureAdapter:
我添加了新类:
@Configuration
@EnableWebMvc
@ComponentScan
public class ViewConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public InternalResourceViewResolver jspViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/WEB-INF/views/");
bean.setSuffix(".jsp");
return bean;
}
}
我的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.paymark</groupId>
<artifactId>paymark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>paymark</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.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>
<java.version>1.8</java.version>
</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- JSTL tag lib -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
文件结构:
我做错了什么?请帮忙
日志:
2017-12-29 15:40:01.756 INFO 12571 --- [ main] com.paymark.app.PaymarkApplication : Starting PaymarkApplication on Karthiks-MacBook-Air.local with PID 12571 (/Applications/MAMP/htdocs/paymark/target/classes started by karthikcp in /Applications/MAMP/htdocs/paymark)
2017-12-29 15:40:01.759 INFO 12571 --- [ main] com.paymark.app.PaymarkApplication : No active profile set, falling back to default profiles: default
2017-12-29 15:40:01.812 INFO 12571 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7f77e91b: startup date [Fri Dec 29 15:40:01 IST 2017]; root of context hierarchy
2017-12-29 15:40:03.035 INFO 12571 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-12-29 15:40:03.048 INFO 12571 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-12-29 15:40:03.049 INFO 12571 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2017-12-29 15:40:03.258 WARN 12571 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/Users/karthikcp/.m2/repository/javax/servlet/jsp/jstl/javax.servlet.jsp.jstl-api/1.2.1/javax.servlet.jsp.jstl-api-1.2.1.jar] from classloader hierarchy
java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method) ~[na:1.8.0_131]
at java.util.zip.ZipFile.access$1400(ZipFile.java:60) ~[na:1.8.0_131]
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:717) ~[na:1.8.0_131]
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:419) ~[na:1.8.0_131]
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158) ~[na:1.8.0_131]
at sun.misc.IOUtils.readFully(IOUtils.java:65) ~[na:1.8.0_131]
at java.util.jar.JarFile.getBytes(JarFile.java:425) ~[na:1.8.0_131]
at java.util.jar.JarFile.getManifestFromReference(JarFile.java:193) ~[na:1.8.0_131]
at java.util.jar.JarFile.getManifest(JarFile.java:180) ~[na:1.8.0_131]
at org.apache.tomcat.util.scan.JarFileUrlJar.getManifest(JarFileUrlJar.java:151) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.processManifest(StandardJarScanner.java:387) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:340) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
2017-12-29 15:40:03.262 WARN 12571 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/Users/karthikcp/.m2/repository/taglibs/standard/1.1.2/standard-1.1.2.jar] from classloader hierarchy
java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method) ~[na:1.8.0_131]
at java.util.zip.ZipFile.access$1400(ZipFile.java:60) ~[na:1.8.0_131]
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:717) ~[na:1.8.0_131]
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:419) ~[na:1.8.0_131]
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158) ~[na:1.8.0_131]
at sun.misc.IOUtils.readFully(IOUtils.java:65) ~[na:1.8.0_131]
at java.util.jar.JarFile.getBytes(JarFile.java:425) ~[na:1.8.0_131]
at java.util.jar.JarFile.getManifestFromReference(JarFile.java:193) ~[na:1.8.0_131]
at java.util.jar.JarFile.getManifest(JarFile.java:180) ~[na:1.8.0_131]
at org.apache.tomcat.util.scan.JarFileUrlJar.getManifest(JarFileUrlJar.java:151) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.processManifest(StandardJarScanner.java:387) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:340) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
2017-12-29 15:40:03.267 INFO 12571 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2017-12-29 15:40:03.269 INFO 12571 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-12-29 15:40:03.270 INFO 12571 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1461 ms
2017-12-29 15:40:03.382 INFO 12571 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-12-29 15:40:03.385 INFO 12571 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-12-29 15:40:03.937 INFO 12571 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-12-29 15:40:03.948 INFO 12571 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-12-29 15:40:04.015 INFO 12571 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2017-12-29 15:40:04.016 INFO 12571 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-12-29 15:40:04.017 INFO 12571 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-12-29 15:40:04.046 INFO 12571 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-12-29 15:40:04.134 INFO 12571 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-12-29 15:40:04.288 INFO 12571 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2017-12-29 15:40:04.292 INFO 12571 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
2017-12-29 15:40:04.307 INFO 12571 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-12-29 15:40:04.408 INFO 12571 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-12-29 15:40:04.409 INFO 12571 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-12-29 15:40:04.440 INFO 12571 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-12-29 15:40:04.444 INFO 12571 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]
2017-12-29 15:40:04.487 INFO 12571 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7f77e91b: startup date [Fri Dec 29 15:40:01 IST 2017]; root of context hierarchy
2017-12-29 15:40:05.046 INFO 12571 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-12-29 15:40:05.107 INFO 12571 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-12-29 15:40:05.111 INFO 12571 --- [ main] com.paymark.app.PaymarkApplication : Started PaymarkApplication in 3.584 seconds (JVM running for 4.494)
尝试@RequestBody注释:
@PostMapping("/hello")
public String sayHello(){
@RequestBody("name) String name, Model model
try with @RequestBody Annotation
}
我坚持使用这个简单的MVC示例。当我启动应用程序并转到localhost:8080时,我得到了“白标签错误页面”,甚至我在“src/main/资源/模板”中创建了“index.html”。我还在我的索引方法上添加了@Request estMap(“/”)。我找不到问题。 : : -在"src/main/资源/模板"下:
下面是我的代码:我正在从application.properties文件swagerconfig.java获取所有值 下面是我的springboot初始值设定项: ServletInitializer.java 日志显示它已映射: 这是我得到的错误:
我不知道如何解决这个问题 spring端:role.java 因此,如果我现在尝试inline=“javascript”: 当我运行它时,我得到这样的响应: 白标签错误页
当我运行spring boot MVC应用程序时,得到以下白标签错误页面。 白标签错误页 此应用程序没有/error的显式映射,因此您将其视为一种后退。 Wed Apr 13 15:45:59 IST 2016出现意外错误(Type=内部服务器错误,Status=500)。循环视图路径[home]:将再次发送回当前处理程序URL[/rewards/web/home]。检查您的ViewResolve
当我使用ide运行我的springboot应用程序时,它工作正常。 但当我运行它的jar时,我得到了白标签错误页面。 白标签错误页面 此应用程序没有 /error的显式映射,因此您将此视为后备。 2018年10月9日星期二15:42:47出现意外错误(类型=未找到,状态=404)/WEB-INF/views/index。jsp
无法使用spring-boot加载非常简单的JSP页面,导致404未找到 HmisApplication.class 主控制器。Java语言 应用属性 pom.xml http://maven.apache.org/xsd/maven-4.0.0.xsd" MVC配置。Java语言 文件结构