[bigdata-042]从头搭建 spring+mvc+boot+tomcat
副标题[/!--empirenews.page--]
3.2 Application.java内容如下 package hello; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; @SpringBootApplication public class Application extends SpringBootServletInitializer{ public static void main(String[] args){ SpringApplication.run(Application.class,args); } } 3.3 GreetingController.java内容如下 package hello; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class GreetingController{ @RequestMapping("/greeting") public String greeting(@RequestParam(value="name",required=false,defaultValue="world") String name,Model model){ model.addAttribute("name",name); return "greeting"; } } <!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>Greeting started</title> <meta http-equiv="Content-Type" content="text/html; chareset=UTF-8"/> </head> <body> <p th:text="'hello,'+${name}+'!'"/> </body> </html> 3.6 pom.xml的内容如下: <?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>org.springframework</groupId> <artifactId>myspringweb</artifactId> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> mvn clean package 提示找不springApplicaiton mvnw clean pacakge 错误: 找不到或无法加载主类 org.apache.maven.wrapper.MavenWrapperMain 解决方式: 将运行正常的那个项目的root目录下的.mvn目录完整复制到本项目下既可。 3.6 运行 java -jar target/myspringweb-0.1.0.jar 3.7 在浏览器输入localhost:8080/greeting,能看到helloworld,功能ok 4. 将3.的项目打包成war包 4.1 参考文档 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#build-tool-plugins-maven-packaging http://blog.csdn.net/javahighness/article/details/52515226 4.2 根据4.1的第二个文档修改,在pom.xml里,增加<packaging>和<dependency>,以及修改Application.java 4.3 pom.xml内容如下 (编辑:百客网 - 百科网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |