spring boot 搭建【搭建基础框架】(一)

来源:互联网 发布:linux gcc编译器下载 编辑:程序博客网 时间:2024/06/05 18:40

一.使用 idea 搭建项目框架

1.file -》 new project -》Spring Initializr    --》next

   

2.选择自己需要的技术 --》next

3.填写自己的工作空间

4.启动 Application 中的main 方法

5.然后报 n多种错误 ,比如你加了jpa ,jdbc  mysql 的依赖会报找不到连接等错(为了启动demo,只能先注释掉效果如下)

<?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>com.heimeiqiu</groupId>   <artifactId>hmq-demo-server</artifactId>   <version>0.0.1-SNAPSHOT</version>   <packaging>war</packaging>   <name>hmq-demo-server</name>   <description>hmq spring boot test demo</description>   <parent>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-parent</artifactId>      <version>1.5.9.RELEASE</version>      <relativePath/> <!-- lookup parent from repository -->   </parent>   <properties>      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>      <java.version>1.8</java.version>      <!--<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>-->   </properties>   <dependencies><!--      <dependency>         <groupId>org.springframework.cloud</groupId>         <artifactId>spring-cloud-starter-eureka</artifactId>      </dependency>      <dependency>         <groupId>org.springframework.cloud</groupId>         <artifactId>spring-cloud-starter-eureka-server</artifactId>      </dependency>-->      <!--<dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-freemarker</artifactId>      </dependency>      <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-jdbc</artifactId>      </dependency>-->      <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-web</artifactId>      </dependency>      <!--   <dependency>                <groupId>mysql</groupId>                <artifactId>mysql-connector-java</artifactId>                <scope>runtime</scope>            </dependency>-->      <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-tomcat</artifactId>         <!--<scope>provided</scope>-->      </dependency>      <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-test</artifactId>         <scope>test</scope>      </dependency>   </dependencies>   <!--<dependencyManagement>      <dependencies>         <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-dependencies</artifactId>            <version>${spring-cloud.version}</version>            <type>pom</type>            <scope>import</scope>         </dependency>      </dependencies>   </dependencyManagement>-->   <build>      <plugins>         <plugin>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-maven-plugin</artifactId>         </plugin>      </plugins>   </build></project>
6重新启动,还是报错,只找到了一种解决办法,但是原理未知

  .mvn
  mvnw
  mvnw.cmd"文件删掉

  将下面代码种的 scope 注释掉

       <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-tomcat</artifactId>         <!--<scope>provided</scope>-->      </dependency>

7.将application 配置添加一些

##selevt 配置#端口server.port=8081#用户访问session过期时间,单位:秒server.session.timeout=1800#配置默认访问路径默认为/server.context-path=/##tomcat配置server.tomcat.uri-encoding=utf-8#最大线程数server.tomcat.max-threads=1000
8编写一个controller

@RestController@EnableAutoConfigurationpublic class TestHelloController {    @RequestMapping("/")    @ResponseBody    String home() {        return "Hello World!";    }}
9.启动测试 Application 中的main 方法

10.浏览器访问

http://localhost:8081/

效果(不会传图片就这么的把)



   


原创粉丝点击