一、idea 使用spring initializr不选择web搭建springboot项目

1.file => new => project

2.直接next到finish结束。

3.完成后创建controller用例测试

4.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cc.ash</groupId>
<artifactId>boot-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-demo</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <!-- 手动添加web依赖,@restController @requestMapping注解等 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

5.application.properties

#端口号修改。默认8080
server.port=

6.springboot入口启动类

package cc.ash.bootdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; @SpringBootApplication
@Controller
public class BootDemoApplication { @RequestMapping("/boot")
@ResponseBody
public String bootTest() { return "hello springboot";
}
public static void main(String[] args) {
SpringApplication.run(BootDemoApplication.class, args);
} }

7.新建包下controller测试类

package cc.ash.bootdemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class TestController { @RequestMapping(name="springboot test", value = "/test")
public String test() {
return "booted";
}
}

8.运行结果

新建包下controller测试类:访问页面

springboot启动类中访问404。改requestMapping、rerun,做了很多操作到怀疑人生。重启idea,世界终于正常了。

能正常访问的结果如下

二、maven搭建springboot项目

1.jdk7的情况下

2.maven搭建

创建完成后的项目结构和pom文件。一个字就是干净

3.手动添加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> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <groupId>cc.ash</groupId>
<artifactId>boot-demo</artifactId>
<version>1.0-SNAPSHOT</version> <properties>
<java.version>1.8</java.version>
</properties> <!-- =================jdk1.7与springboot版本不兼容======================= -->
<!--<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.myproject.Application</start-class>
</properties>--> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <!-- 手动添加web依赖,@restController @requestMapping注解等 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

maven导入依赖(未选择自动导入的情况下)。

4.编写测试用例代码

1).测试controller:

  TestController

package cc.ash.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; @RestController
public class TestController { @RequestMapping(name="maven手动创建springboot",value={"/manual", "mvnManual"})
@ResponseBody
public String test() { return "maven manual";
} }

2.启动入口:

DemoApplication
package cc.ash;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

3.完成后代码结构

5.访问测试

6.jdk1.7错误留存

不兼容问题

https://blog.csdn.net/wj197927/article/details/79557017

https://www.jianshu.com/p/95d8a0cf0244

idea日志记录(非控制台日志,控制台日志如上)

7.springboot项目结构导致controller访问404的问题

自建的所有需要扫描注解的类,必须与启动类的包平级或者在其之下。如启动类在包【aa.bb】,其他需要扫描的类必须在【aa.bb】中或【aa.bb】之下的包里。

参考链接:

详细说明的:https://www.cnblogs.com/remember-me/p/10091126.html

直接上解决方法的:https://blog.csdn.net/dong__CSDN/article/details/85342180

idea:spring initializr无web勾选,maven方式搭建springboot项目。jdk7创建springboot项目的版本不兼容问题。的更多相关文章

  1. 【Web】Eclipse + Maven + Struts搭建服务器

    一.环境 系统:Windows7 IDE:Eclipse-Kepler Service Release 2 使用插件:Maven(请预先在电脑上安装Maven) 二.搭建 在Eclipse中新建一个M ...

  2. Spring Boot的web开发&静态资源配置方式

    Web开发的自动配置类:org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration 1.1. 自动配置的ViewResolve ...

  3. idea拉取git项目并创建为maven项目(新创建github项目)

    0 环境 系统环境:win10 编辑器:idea 1 正文 1 clone项目 跟着提示yes 下一步 2 在根节点添加pom.xml(maven) <?xml version="1. ...

  4. 在线官网Spring Initializr 或 IntelliJ IDEA 快速搭建springboot项目

    Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 那么,如何快速新建一个一个spring ...

  5. 二:动手实操SpringBoot-使用Spring Initializr创建项目

    使用 Spring Initializr 初始化 Spring Boot 项目 Spring Initializr 从本质上说就是一个Web应用程序,它能为你构建Spring Boot项目结构. 虽然 ...

  6. MyEclipse创建SSH项目(Java web由maven管理)

    JavaEE后台开发,MyEclipse创建SSH项目,MyEclipse创建Java web 由maven管理的SSH项目. Demo工程源码github地址 1.创建SSH项目 1.创建web工程 ...

  7. IDEA用maven创建springMVC项目和配置

    工具准备:IDEA2016.3 Java jdk 1.8 1.DEA创建项目 新建一个maven project,并且选择webapp原型.  然后点击next  这里的GroupId和Artifac ...

  8. IDEA用maven创建springMVC项目和配置(XML配置和Java配置)

    1.DEA创建项目 新建一个maven project,并且选择webapp原型. 然后点击next 这里的GroupId和ArtifactID随意填写,但是ArtifactID最好和你的项目一名一样 ...

  9. Maven搭建SpringMVC+MyBatis+Json项目(多模块项目)

    一.开发环境 Eclipse:eclipse-jee-luna-SR1a-win32; JDK:jdk-8u121-windows-i586.exe; MySql:MySQL Server 5.5; ...

随机推荐

  1. docker笔记、常遇问题、常用命令

    启动一个容器并且进到里面,退出后,容器结束 [root@bogon ~]# docker run --name mynginx -it nginx 启动一个容器,退出后自动删除 [root@bogon ...

  2. cmake生成Makefile时指定c/c++编译器

    cmake .. -DCMAKE_CXX_COMPILER:FILEPATH=/usr/local/bin/g++ -DCMAKE_C_COMPILER:FILEPATH=/usr/local/bin ...

  3. 083. Remove Duplicates from Sorted List

    题目链接:https://leetcode.com/problems/rotate-list/description/ Given a sorted linked list, delete all d ...

  4. localStorage基本了解及使用

    以下内容来自: https://www.cnblogs.com/st-leslie/p/5617130.html  感谢大佬的分享 一.什么是localStorage.sessionStorage 在 ...

  5. centos 7.3镜像制作

    1.在KVM环境上准备虚拟机磁盘 [root@localhost ~]# qemu-img create -f qcow2 -o size=50G /opt/CentOS-7-1511-x86_64_ ...

  6. ‘No module named 'numpy.core._multiarray_umath’ 或者‘no module named numpy’

    在import TensorFlow时,如果遇到‘No module named 'numpy.core._multiarray_umath’ 或者‘no module named numpy’,大多 ...

  7. (转)python基础学习-----生成器和迭代器

    在Python中,很多对象都是可以通过for语句来直接遍历的,例如list.string.dict等等,这些对象都可以被称为可迭代对象.至于说哪些对象是可以被迭代访问的,就要了解一下迭代器相关的知识了 ...

  8. PostgreSQL查看等待锁的SQL和进程

    查看等待锁的查询和进程: The following query may be helpful to see what processes are blocking SQL statements (t ...

  9. 从零开始,SpreadJS新人学习笔记【第5周】

    复制粘贴.单元格格式和单元格类型 本周,让我们一起来学习SpreadJS 的复制粘贴.单元格格式和单元格类型,希望我的学习笔记能够帮助你们,从零开始学习 SpreadJS,并逐步精通. 在此前的学习笔 ...

  10. 平面割线平分点(构造)--牛客第三场-- Magic Line

    题意: 给你n个点的坐标,让你给出两个点,这两个点的连线可以平分这些点. 思路: 先按y的大小排序,在按x的小排序,再搞一下就行了.如下图: #include <bits/stdc++.h> ...