第一个Spring-boot
Eclipse创建第一个Spring-boot项目
进入Eclipse软件中选择 File->new->other或者快捷键Ctrl+N
Next->Next 到这里选择蓝色这个Webapp选项在点next
我创建一个项目,我一般会将GroupId设置为Demo,,ArtifactId设置为tes,表示你这个项目的名称是testProj,依照这个设置,在你创建Maven工程后,新建包的时候,包结构最好是Demo.tes打头的,如果有个controller,它的全路径就是Demo.tes.controller
项目创建完成的目录结构,需要pom.xml文件,在最后面!
StartSpringBootApplication是项目的启动代码,Spring-boot是内置tomcat 的
且这个类要在目录最顶层否则你注解的其他类它扫描不到
@SpringBootApplication
public class StartSpringBootApplication{
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
}
}
DemoController 类 中@RestController=@ResponseBody+@Controller返回Json字符串 @RequestMapping("/") 则是请求路径详情参考
@RestController
public class DemoController {
@RequestMapping("/")
String getHelloWord(){
return "Hello Word";
}
}
http://localhost:8080/加上你在@RequestMapping("/")写的路径出现这个页面就证明成功了!
附带上pom.xml文件
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Demo</groupId>
<artifactId>tes</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>tes Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<!--HTTP jar -->
<version.httpmime>4.3.1</version.httpmime>
<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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<finalName>xiaowei</finalName>
</build>
</project>
第一次写博客大家多多包涵,多多交流谢谢!有什么问题留言呀