问题
如题,springboot项目,在idea运行无问题,如图:
此处地址栏为 localhost:8080
但当我将项目打包为jar通过java -jar运行的时候,虽然能正常部署但controller接口却报404错误,如图:
此处地址栏为 服务器ip:8080
部分代码
controller
package net.suncaper.epidemicdataanalysis.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/uv")
public class ChinaDayController {
@Autowired
private JdbcTemplate jdbcTemplate;
@GetMapping("chinaData")
@ResponseBody
public List<Map<String, Object>> listUvCovid(){
//中国每日各省份数据
String sql = "select * from chn_data_per_province_by_date";
return jdbcTemplate.queryForList(sql);
}
@GetMapping("chinaCure")
@ResponseBody
public List<Map<String, Object>> listCure(){
//中国每日各省份数据
String sql = "select * from chn_cure_rate_per_province";
return jdbcTemplate.queryForList(sql);
}
@GetMapping("chinaDeath")
@ResponseBody
public List<Map<String, Object>> listDeath(){
//中国每日各省份数据
String sql = "select * from chn_death_rate_per_province";
return jdbcTemplate.queryForList(sql);
}
@GetMapping("chinaLineChart")
@ResponseBody
public List<Map<String, Object>> listLineChart(){
String sql = "select * from china_line_chart";
return jdbcTemplate.queryForList(sql);
}
}
application
package net.suncaper.epidemicdataanalysis;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EpidemicDataAnalysisApplication {
public static void main(String[] args) {
SpringApplication.run(EpidemicDataAnalysisApplication.class, args);
}
}
pom
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.tld</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>