Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

java - What set of commands to use for running Spring Boot Application in Visual Studio Code from terminal?

I am new to Spring Boot. In Visual Studio Code, I have to create a standalone jar executable which will print the list of people in sorted order by name, age and experience.

application.properties: (this was already written in the question) spring.datasource.driver-class-name=org.h2.Driver

pom.xml:

<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>springBoot</groupId>
    <artifactId>frescoCourses</artifactId>
    <version>0.1.0</version>
    <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-test</artifactId>
             <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

My code: EmployeeService Class

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {
     public List<Employee> getEmployees() {
        List<Employee> emp = new ArrayList<>();
        Employee emp1 = new Employee("Sandhya",20,0);
        Employee emp2 = new Employee("Kemp",24,2);
        Employee emp3 = new Employee("Anil",22,3);
        Employee emp4 = new Employee("Kumar",30,6);
        Employee emp5 = new Employee("Tim",32,7);
        emp.add(emp1);
        emp.add(emp2);
        emp.add(emp3);
        emp.add(emp4);
        emp.add(emp5);

        return emp;
    }
}

EmployeeController Class

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmployeeController {

  @Autowired
  EmployeeService employeeService;

  @RequestMapping("/")
    public List<Employee> getEmpList(){
    List<Employee> empController = employeeService.getEmployees();
    Collections.sort(empController);
        return empController;
    }

}

DemoApplication

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

Employee Class

public class Employee implements Comparable<Employee> {

private String name;
private int age;
private int exp;

public Employee(String name, int age, int exp) {
    super();
    this.name = name;
    this.age = age;
    this.exp = exp;
}

@Override
public int compareTo(Employee emp) {
//the comparator logic which I am able to write}}

On clicking Run it shows "Build Failure". Failed to execute goal org.apache.maven.plugins. maven-resources-plugin3.1.0:(resources)(default resources) on Test/....../application.properties [Permission denied]

Kindly help.

error image of terminal


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...