@SpringBootApplication公共类 SpringApiApplication 扩展了 SpringBootServlet初始化器实现 Web应用程序初始化器 { @Override受保护的 SpringApplicationBuilder configure(SpringApplicationBuilder 应用程序) { 返回 application.sources(SpringApiApplication.class); } 公共静态 void main(字符串[] args) 抛出异常{ SpringApplication.run(SpringApiApplication.class, args); } }
*This is my controller page*
package com.javaproject.springapi.controller;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.javaproject.springapi.model.Student;
import com.javaproject.springapi.service.StudentService;
@RestController
@RequestMapping("/api" )
public class StudentController {
private StudentService studentService;
public StudentController(StudentService studentService) {
super();
this.studentService = studentService;
}
@PostMapping()
public ResponseEntity< Student> addStudent(@RequestBody Student student){
return new ResponseEntity<Student> (studentService.addStudent(student),HttpStatus.CREATED);
}
@GetMapping
public List<Student> getStudents(){
return studentService.getStudents();
}
* get student by id*
@GetMapping("{id}")
public ResponseEntity<Student> getStudentById(@PathVariable("id")long stuId){
return new ResponseEntity<Student>(studentService.getStudentById(stuId),HttpStatus.OK);
}
*Update Method*
@PutMapping("{id}")
public ResponseEntity<Student> updateStudent(@PathVariable("id")long id
,@RequestBody Student student){
return new ResponseEntity<Student> (studentService.updateStudent(student, id),HttpStatus.OK);
}
* //Build Delete Method*
@DeleteMapping("{id}")
public ResponseEntity<String> deleteStudent(@PathVariable("id")long id){
studentService.deleteStudent(id);
return new ResponseEntity<String>("Employee Deleted Successfully!.",HttpStatus.OK);
}
}
这是我的 pom.xml 4.0.0 组织.springframework.boot Spring启动器-父级 2.7.3 com.springboot.app Spring靴-战争-演示 0.0.1-快照 *我创建了一个战争 * 战争Spring靴-战争-战争-演示 Spring靴-战争-演示 Spring靴 战争演示
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>demo</finalName>
</build>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
========
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@RestController
@RequestMapping("/api")
public class StudentController {
@GetMapping("/students")
public List<Student> getStudents() {
Student.builder().id(1).name("test").build();
return Stream.of(Student.builder().id(1).name("test").build()).collect(Collectors.toList());
}
}
=======
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class Student {
private long id;
private String name;
}
部署的外部tomcat应用程序日志
从浏览器访问endpoint
错误:命令错误,退出状态为1:Command://app/.heroku/python/bin/python/app/.heroku/python/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel/tmp/tmp3b4z4ntu cwd://tmp/pip-i
问题内容: 嗨伙计, 如何在Eclipse中创建我的应用程序的exe文件?请提及要遵循的步骤。 谢谢 问题答案: 如果您只是想知道如何在Eclipse IDE外部运行应用程序,则不需要exe。在菜单中寻找“导出JAR”选项。 如果导出正确完成(生成了MANIFEST),则应该能够通过双击JAR文件或从命令行使用“ java -jar FILENAME.jar”来运行JAR文件。请注意,这是与平台无
请参见日志文件2017-11-06 23:34:15下面的代码调试DispatcherServlet:861 -名为“Spring”的DispatcherServlet处理[/Insurance1/]的GET请求17-11-06 23:34:15 WARN page not found:1136-在名为“Spring”的DispatcherServlet中找不到具有URI[/insurace 1/
我这里有一个小问题,如果我想在Android Studio中构建一个APK,我会得到这个错误消息: 这是我的分级文件:
我的控制台出现以下错误,请帮助我,在发布到应用商店有什么问题吗?(我为我的英语道歉&这是我第一个使用android studio的应用程序)更多信息