springBoot入门

整合玩ssm ,折腾springboot,对着官网,别人的demo 看着简单,自己操作起来 一堆错误。

环境IDEA,maven,过程不演示 ,

file=>new project=>mavent(不用选择模板)=>next=> 填写groupid,artifactid 后next> next........

新建一个Hellocontroller, HelloApplication

最后工程如图:

 

 

 

 

pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
    </parent>

    <!--导入springBoot 的依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <!--Creating an Executable Jar-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
View Code

HelloController
/**
 * Create by  on 2019-09-26
 *  RestController 是@Controller @ResponseBody组合体
 * @author lsw
 */
@RestController
public class HelloController {

    @RequestMapping("/hello")
    String hello() {
        return "Hello World!";
    }
}
View Code

HelloApplication

/**
 * Create by  on 2019-09-26
 * SpringBootApplication 标注这是个springBoot 运用
 * @author lsw
 */
@SpringBootApplication
public class HelloApplication {

    public static void main(String[] args) {
        SpringApplication.run( HelloApplication.class, args);
    }

}
View Code

 

汇总遇到的问题:

Caused by: java.net.BindException: Address already in use: bind

好吧 端口占用了 网上有的杀死端口  。解决办法:

resources目录下新建 application.properties 文件 内容: server.port=8088


错误2:
Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package
好吧大概意思测试类 没有在包下面 啥spring 容器注册的时候xxxx
解决方案:
https://blog.csdn.net/qq_15071263/article/details/78459087
https://www.cnblogs.com/gudi/p/7892769.html


 参考资料:

https://docs.spring.io/spring-boot/docs/2.1.8.RELEASE/reference/html/getting-started-first-application.html#getting-started-first-application-pom

posted @ 2019-09-26 18:06  s_p  阅读(209)  评论(0编辑  收藏  举报