1、springboot的部署

环境:eclipse 

1、新建一个maven项目(注意是jar而不是war,springboot是打包成jar的),勾选如下所示


2、根据需要导入所需对应的依赖(我这里导入了mysql、aop、springjdbc的依赖,不需要可以删除),并且update maven project

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.2.RELEASE</version>
	</parent>
	<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-thymeleaf</artifactId>
	</dependency>
			<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!-- aop -->
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>

3、新建一个启动Controller,运行项目时直接执行main方法就可以了,不过此时还没有暴露访问的接口,接第4步

@SpringBootApplication
public class Run{
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Run.class, args);
    }
}

4、新建入口Controller,接下来启动Run的main方法,接着在网址输入http://localhost:8080/。可看到成功输出helloworld

@Controller
public class EntranceController {
	
    @RequestMapping("/")
    @ResponseBody
    String helloworld() {
        return "helloworld";
    }
	
	
}


猜你喜欢

转载自blog.csdn.net/huang7511389/article/details/80868005