我正在尝试从服务实现类中获取@autowire存储库引用,但仍然出现未找到bean错误
我已经尝试在父级中移动App.java文件
App.java
root.clipboard_clear()
root.clipboard_append(entry.get())
VehicleService.java
package com.trucker;
import org.springframework.context.ApplicationContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App
{
public static void main( String[] args ){
ApplicationContext applicationContext = SpringApplication.run(App.class,args);
}
}
VehicleRepositoryInterface.java
package com.trucker.service;
import com.trucker.entity.Vehicle;
import com.trucker.repository.VehicleRepositoryInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class VehicleService implements VehicleServiceI {
@Autowired
VehicleRepositoryInterface vehicleRepository;
@Override
public Vehicle addVehicles(Vehicle vehicle) {
System.out.println(vehicle);
return vehicleRepository.save(vehicle);
}
}
VehicleController.java
package com.trucker.repository;
import com.trucker.entity.Vehicle;
import org.springframework.context.annotation.Bean;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
public interface VehicleRepositoryInterface extends CrudRepository<Vehicle,String> {
}
Vehicle.java
package com.trucker.controller;
import com.trucker.entity.Vehicle;
import com.trucker.service.VehicleServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class VehicleController {
@Autowired
VehicleServiceI vehicleService;
@RequestMapping(path = "/vehicles", method = RequestMethod.PUT)
public String addVehicles(@RequestBody Vehicle vehicle) {
System.out.println("************IN THE CONTROLLER************"+vehicle);
vehicleService.addVehicles(vehicle);
return "";
}
}
application.properties
package com.trucker.entity;
import javax.persistence.Entity;
import java.sql.Timestamp;
import javax.persistence.Id;
@Entity
public class Vehicle {
@Id
String vin;
String make;
String model;
int year;
int redlineRpm;
int maxFuelVolume;
Timestamp lastServiceDate;
public String getVin() {
return vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getRedlineRpm() {
return redlineRpm;
}
public void setRedlineRpm(int redlineRpm) {
this.redlineRpm = redlineRpm;
}
public int getMaxFuelVolume() {
return maxFuelVolume;
}
public void setMaxFuelVolume(int maxFuelVolume) {
this.maxFuelVolume = maxFuelVolume;
}
public Timestamp getLastServiceDate() {
return lastServiceDate;
}
public void setLastServiceDate(Timestamp lastServiceDate) {
this.lastServiceDate = lastServiceDate;
}
@Override
public String toString() {
return "Vehicle{" +
"vin='" + vin + '\'' +
", make='" + make + '\'' +
", model='" + model + '\'' +
", year=" + year +
", redlineRpm=" + redlineRpm +
", maxFuelVolume=" + maxFuelVolume +
", lastServiceDate=" + lastServiceDate +
'}';
}
}
目录结构:
application.properties
server.port=8084
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver
spring.datasource.username=system
spring.datasource.password=system
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
答案 0 :(得分:0)