即使在我向类中添加了@component、@service和@repository注释之后,我的代码也会出现这种情况:
这是它的资源:
package app.gym.v1.Resource.API;
import app.gym.v1.Model.Domain.Gym;
import app.gym.v1.Service.GymService;
import app.gym.v1.Utility.Constant.SwaggerConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static org.springframework.http.HttpStatus.OK;
@RestController
@RequestMapping(path = "/gym")
@Api(tags = {SwaggerConstant.API_TAG3})
public class GymControl {
private GymService gymService;
@Autowired
public GymControl(GymService gymService) {
this.gymService = gymService;
}
@ApiOperation(value = "Get all available gyms", notes = "Retrieve a list of all gyms")
@ApiResponses({@ApiResponse(responseCode = "200", description = "The list of gyms retrieved"),
@ApiResponse(responseCode = "400", description = "The request is malformed or invalid"),
@ApiResponse(responseCode = "404", description = "The resource URL was not found on the server"),
@ApiResponse(responseCode = "500", description = "An internal server error occurred"),
@ApiResponse(responseCode = "403", description = "You are not authorized. Please authenticate and try again"),
@ApiResponse(responseCode = "401", description = "You don't have permission to this resource")
})
@GetMapping("/list_gym")
public ResponseEntity<List<Gym>> getAllGyms() {
List<Gym> gyms = gymService.getGyms();
return new ResponseEntity<>(gyms, OK);
}
@ApiOperation(value = "Finding gym from list", notes = "Retrieve a gym from the search engine")
@ApiResponses({@ApiResponse(responseCode = "200", description = "The gym was found"),
@ApiResponse(responseCode = "400", description = "The request is malformed or invalid"),
@ApiResponse(responseCode = "404", description = "The resource URL was not found on the server"),
@ApiResponse(responseCode = "500", description = "An internal server error occurred"),
@ApiResponse(responseCode = "403", description = "You are not authorized. Please authenticate and try again"),
@ApiResponse(responseCode = "401", description = "You don't have permission to this resource")
})
@GetMapping("/find/{gymName}")
public ResponseEntity<Gym> getGym(@PathVariable("gymName") String gymName) {
Gym gym = gymService.findGymByGymName(gymName);
return new ResponseEntity<>(gym, OK);
}
}
package app.gym.v1.Repo;
import app.gym.v1.Model.Domain.Gym;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface GymRepo extends JpaRepository<Gym, Long> {
Gym findByGymName(String gymName);
}
package app.gym.v1.Service;
import app.gym.v1.Model.Domain.Gym;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public interface GymService {
List<Gym> getGyms();
Gym findGymByGymName(String gymName);
}
说明:
找不到app.gym.v1.resource.api.GymControl中构造函数的参数0需要类型为“app.gym.v1.service.GymService”的bean。
行动:
@Service注释应该保存在哪里?接口还是实现?你必须检查这个。基本上你需要实现GymService接口,然后只有它才会工作,像这样尝试。
@Service
public class GymServiceImpl implements GymService{
@Autowired
GymRepo gymRepo
@Override
public List<Gym> getGyms() {
// TODO Auto-generated method stub
return gymRepo.findAll();
}
@Override
public Gym findGymByGymName(String gymName) {
// TODO Auto-generated method stub
return gymRepo.findByGymName(gymName);
}
}
描述:com.mongotest.demo.seeder中构造函数的参数0需要类型为“com.mongotest.repositories.studentrepository”的bean,但找不到该bean。 pom.xml
我有一个Java Spring Boot项目,我正在其中创建一个post请求。代码如下所示: 主要: 但是,当我运行该项目时,我会得到以下错误: 感谢您对此的任何帮助!非常感谢,
下午好,我正在尝试使用Spring Boot运行SOAP服务,但出现以下错误: 应用程序启动失败 描述: 我知道也许这应该是个愚蠢的错误,但我看不出来 附件MI代码: SpringBootSoapApp.java ClienteServiceImpl.java client.xsd 应用程序.属性 我的项目结构 我试图遵循以下示例:https://www.javaspringclub.com/pu
当我运行main类时会出错。 错误: 主类: 我的包裹是这样的:
我有 ProductController.java ProductService.java ProductServiceImpl.java 这是我的错误: 我有完整日志:https://gist.github.com/donhuvy/b918e20eeeb7cbe3c4be4167d066f7fd 这是我的完整源代码https://github.com/donhuvy/accounting/com