spring boot 它的设计目的就是为例简化开发,开启了各种自动装配,你不想写各种配置文件,引入相关的依赖就能迅速搭建起一个web工程。它采用的是建立生产就绪的应用程序观点,优先于配置的惯例。
超过十年行业经验,技术领先,服务至上的经营模式,全靠网络和口碑获得客户,为自己降低成本,也就是为客户降低成本。到目前业务范围包括了:做网站、网站建设,成都网站推广,成都网站优化,整体网络托管,微信平台小程序开发,微信开发,重庆App定制开发,同时也可以让客户的网站和网络营销和我们一样获得订单和生意!
<?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.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.honghh</groupId>
<artifactId>boot-first</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-first</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-web</artifactId>
</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>
package com.honghh.bootfirst.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* ClassName: HelloWordController
* Description:
*
* @author honghh
* @date 2019/02/19 15:58
*/
@RestController
public class HelloWordController {
@RequestMapping("/")
public String index() {
return "Hello Spring Boot!";
}
}
启动项目,在浏览器中输入: http://localhost:8080/
启动成功,第一个springboot项目搭建成功!
但是这个要注意一个点,现在我的controller是写在com.honghh.bootfirst下的,所以没有问题,我们将controller包放在com.honghh.controller下执行你会发现报404
那我们应该怎么解决呢?
Spring Boot 正常启动后访问Controller提示404
以启动类的包路径作为顶层包路径,列如启动类包为com.honghh.bootfirst,那么Controller包路径就为com.honghh.bootfirst.controller。
在启动上方添加@ComponentScan注解,此注解为指定扫描路径,例如:
@ComponentScan(basePackages = {"com.honghh.*"}) #多个不同的以逗号分割。
package com.honghh.bootfirst;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan(basePackages = {"com.honghh.*"})
@SpringBootApplication
public class BootFirstApplication {
public static void main(String[] args) {
SpringApplication.run(BootFirstApplication.class, args);
}
}
文章来源: https://blog.csdn.net/qq_35098526/article/details/87715317
本文名称:四、创建第一个springboot项目
转载源于:https://www.cdcxhl.com/article8/pjshop.html
成都网站建设公司_创新互联,为您提供搜索引擎优化、定制网站、面包屑导航、自适应网站、手机网站建设、定制开发
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联