修改方法
在pom.xml文件中添加下面的依赖:
<!--因配置外部TOMCAT 而配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
同时,将pom.xml文件首部的jar改成war
<groupId>com.star</groupId>
<artifactId>yiyong</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!--<packaging>jar</packaging>-->
最后,修改启动类
@SpringBootApplication
@MapperScan(value = {"com.example.demo.mapper"})
public class DemoApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
//ConfigurableApplicationContext configurableApplicationContext = SpringApplication.run(DemoApplication.class, args);
//SpringContextUtil.setApplicationContext(configurableApplicationContext);
//LightTemperatureAndHumidityService bean = (LightTemperatureAndHumidityService)configurableApplicationContext.getBean();
//NIOClient client = new NIOClient();
//client.initClient("121.1.1.1", 19910);//服务器ip,端口号,服务器启动后,连接下位机服务器,接收数据
//client.listen();
}
}
打包部署
在IDEA右侧Maven栏双击package等待Build Success即可。
ok 整个步骤就是这样 然后把target目录下的war包放到tomcat的webapps目录下,启动tomcat,即可自动解压部署。 最后在浏览器中输入
http://localhost:[端口号]/[打包项目名]/
注意: 如果访问出现404 这可能是访问的路径出问题了。这没有打包之前,是可以不带项目名进行访问的,在打包之后是需要war的名称的。