есть ошибка в основном классе приложения весенней загрузки. Ошибка приведена ниже. Моя программа не будет работать. Пожалуйста, помогите мне решить эту проблему.
Multiple markers at this line
- The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
- The method run(Object, String...) from the type SpringApplication refers to the missing type
ConfigurableApplicationContext
POM
<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>
<groupId>com.letsstartcoding</groupId>
<artifactId>springbootexample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<!-- **<version>1.3.6.RELEASE</version> // update this to latest**
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
employee. java
package com.springboot;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/*import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
*/
@Entity
@Table(name="Employees")
@EntityListeners(AuditingEntityListener.class)
public class Employee {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
@NotBlank
private String name;
@NotBlank
private String designation;
@NotBlank
@Temporal(TemporalType.TIMESTAMP)
@LastModifiedDate
private Date createdAt;
@NotBlank
private String expertise;
public String getExpertise() {
return expertise;
}
public void setExpertise(String expertise) {
this.expertise = expertise;
}
}
Employeedao. java
в этот класс дао я включил код для удаления и обновления вставки пакета com.dao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.repository.EmployeeRepository;
import com.springboot.Employee;
@Service
public class EmployeeDAO {
@Autowired
static
EmployeeRepository employeeRepository;
/*save employee*/
public static Employee save(Employee emp) {
return employeeRepository.save(emp);
}
/*search an employee*/
public List<Employee> findAll(){
return employeeRepository.findAll();
}
/*get an employee by Id*/
public Employee findOne(Long empid) {
return employeeRepository.findOne(empid);/*getOne*/
}
/* delete an employee*/
public void delete(Employee emp) {
employeeRepository.delete(emp);
}
/*update an employee*/
}
класс контроллера ..... с комментариями я объяснил детали.
Я должен проверить это с помощью почтальона. #
package com.Controller;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
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.dao.EmployeeDAO;
import com.springboot.Employee;
@RestController
@RequestMapping("/company")
public class EmployeeController {
@Autowired
EmployeeDAO employeeDAO;
/* save an employee*/
@PostMapping("/employees")
public Employee createEmployee(@Valid @RequestBody Employee emp) {
return employeeDAO.save(emp);}
/*get all employees*/
@GetMapping("/employees")
public List<Employee> getAllEmployees(){
return employeeDAO.findAll();
}
/*get employee by empid*/
@GetMapping("/employees/(id)")
public ResponseEntity<Employee> getEmployeeById(@PathVariable(value="id") Long empid){
Employee emp = employeeDAO.findOne(empid);
if(emp==null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok().body(emp);
}
/*update an employee*/
@PutMapping("/employees/(id)")
public ResponseEntity<Employee> updateEmployee(@PathVariable(value="id") Long empid, @Valid @RequestBody Employee empDetails ){
Employee emp = employeeDAO.findOne(empid);
if(emp==null) {
return ResponseEntity.notFound().build();
}
emp.setName(empDetails.getName());
emp.setDesignation(empDetails.getDesignation());
emp.setExpertise(empDetails.getExpertise());
EmployeeDAO ed = new EmployeeDAO();
Employee updateEmployee = ed.save(emp);
return ResponseEntity.ok().body(updateEmployee);
}
/*delete an employee*/
@DeleteMapping("/employees/{id}")
public ResponseEntity<Employee> deleteEmployee(@PathVariable(value="id") Long empid ){
Employee emp = employeeDAO.findOne(empid);
if(emp==null) {
return ResponseEntity.notFound().build();
}
employeeDAO.delete(emp);
return ResponseEntity.ok().build();
}}
##main application class ##
** Spring Boot,Restful API,JPA, Hibernate, MySQL CRUD.basic program**
package com.restapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@EnableAutoConfiguration
@SpringBootApplication
@EnableJpaAuditing
public class EmployeeApplication {
public static void main(String[] args) {
SpringApplication.run( EmployeeApplication.class, args);
}
}
aplication.properties.file
Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url= jdbc:mysql://localhost:3306/sakila?useSSL=false
spring.datasource.username=myusername
spring.datasource.password=mypassword
Свойства гибернации
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MYSQL5Dialect
spring.jpa.hibernate.ddl-auto= update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver