zoukankan      html  css  js  c++  java
  • SpringBoot学习(六)

    1、pom 文件

    复制代码
    <?xml version="1.0" encoding="utf-8"?>
    <dependencies> 
      <dependency> 
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-web</artifactId> 
      </dependency>  
      <dependency> 
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-tomcat</artifactId>  
        <scope>provided</scope> 
      </dependency>  
      <dependency> 
        <groupId>org.apache.tomcat.embed</groupId>  
        <artifactId>tomcat-embed-jasper</artifactId> 
      </dependency>  
      <dependency> 
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-test</artifactId>  
        <scope>test</scope> 
      </dependency> 
    </dependencies>
    复制代码

    2、application.properties 文件

    # 页面默认前缀目录
    spring.mvc.view.prefix=/WEB-INF/jsp/
    # 响应页面默认后缀 spring.mvc.view.suffix=.jsp # 自定义属性,可以在Controller中读取 application.hello=Hello GOD

    3、Controller 文件

    复制代码
    package com.example;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    import java.util.Map; /**
     * Created by Gensis on 2016/9/9. */ @Controller public class HelloController { // 从 application.properties 中读取配置,如取不到默认值为Hello
        @Value("${application.hello:Hello}") private String hello;
    
        @RequestMapping("/helloJsp") public String helloJsp(Map map) {
            System.out.println("HelloController.helloJsp().hello=" + hello);
            map.put("hello", hello); return "helloJsp";
    
        }
    
    }
    复制代码

    4、jsp 页面

    <%@<a href='http://bbs.itmayiedu.com/member/'></a> page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" %>
    "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
    
    "Content-Type" content="text/html; charset=UTF-8">GOD
     helloJsp  ${hello} 

    5、遇到的问题

    1、Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

      把pom中所有的provided注释掉
    

    2、报 404

      <1>注意controller和restcontroller区别
    
      <2>检查application.properties
    
      <3>检查pom是否缺支持jsp包
    
    
    ## 3、Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
    
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.SampleWebJspApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:187) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]
        at com.example.SampleWebJspApplication.main(SampleWebJspApplication.java:20) [classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_77]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_77]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_77]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_77]
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na]
    Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
        at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:301) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:237) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:204) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
        ... 17 common frames omitted
    
    
    

    作者:GOD

    出处:GOD 的博客–http://www.cnblogs.com/God-/

    您的支持是对博主最大的鼓励,感谢您的认真阅读。

  • 相关阅读:
    directX--关于CSource和CSourceStream (谁调用了fillbuffer) 分类: DirectX 2014-11-11 08:10 635人阅读 评论(0) 收藏
    把连续动态bmp转换为avi 分类: 文件格式 VC++ ffmpeg-SDL-VLC-Live555 DirectX 2014-11-07 14:54 516人阅读 评论(0) 收藏
    ioftpd read/write 锁实现
    编译 ioftpd v7.7.3
    3D Math Primer for Graphics and Game Development -- 图形与游戏开发(3D数学基础) (简介)
    E. Turn Off The TV Educational Codeforces Round 29
    D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
    D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
    D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
    E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)
  • 原文地址:https://www.cnblogs.com/yujihaia/p/7367572.html
Copyright © 2011-2022 走看看