postman Sping Boot 微服务Intellij不工作

6za6bjd0  于 2022-11-07  发布在  Postman
关注(0)|答案(2)|浏览(156)

你好,我是SpringBoot的新手,我创建了这个微服务,但它不起作用。当我试图运行一个与 Postman 的获取时,我得到了这个错误,你能帮助我吗?

"timestamp": "2022-09-29T15:24:02.783+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "trace": "org.springframework.data.crossstore.ChangeSetPersister$NotFoundException\r\n\tat com.poste.anagrafica.controller.UserController.listUserByRegistrationNumber(UserController.java:45)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:566)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)\r\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\r\n\tat org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:655)\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:764)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)\r\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)\r\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\r\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1789)\r\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\r\n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)\r\n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat java.base/java.lang.Thread.run(Thread.java:829)\r\n",
    "message": "No message available",
    "path": "/user/cerca/ciao"
}

我附加了类
这是数据库

类实体

@Entity
    @Table(name = "USERS")
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Getter
    @Setter

    public class User implements Serializable {
    @Id
    @Column(name = "user_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "created_date")
    private LocalDateTime createdDate;

    @Column(name = "deleted", nullable = false)
    private Long number;

    @Column(name = "modified_date")
    private LocalDateTime modifiedDate;

    @Column(name = "birth_place")
    private String birthPlace;

    @Column(name = "birthday")
    private Date birthDay;

    @Column(name = "canNominate")
    private Long canNominate;

    @Column(name = "email")
    private String email;

    @Column(name = "firstName")
    private String firstName;

    @Column(name= "fiscalCode")
    private String fiscalCode;

    @Column(name = "hiringDate")
    private Date hiringDate;

    @Column(name ="last_name")
    private String lastName;

    @Column(name = "matricola")
    private String matricola;

    @Column(name = "position")
    private String position;

    @Column(name = "registration_number")
    private String registrationNumber;

    @Column(name = "replaced")
    private Long replaced;

    @Column(name = "terminationDate")
    private Date terminationDate;

    @Column(name = "user_status")
    private String userStatus;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "application_role_id")
    private Role applicationRoleID;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id")
    private Company companyID;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "direction_id")
    private Direction directions ;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "level_id")
    private Levels levelID;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "referent_id")
    private User referentID;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "role_id")
    private Role roleID;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "task_id")
    private EmployeeTask taskID;

}

控制器类,用于配置端点和必要的方法

@RestController
    @RequestMapping("/user")
    @Log
    public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    UserService userService;

    @GetMapping(value = "/cerca/{registration_number}", produces = "application/json")
    public ResponseEntity<UserDto> listUserByRegistrationNumber(@PathVariable("registration_Number") String registrationNumber)
            throws ChangeSetPersister.NotFoundException
    {
        log.info("******Ottengo l'user con numeroRegistrazione " + registrationNumber + "*******");

        UserDto user = userService.SelByRegistrationNumber(registrationNumber);

        if (user == null)
        {
            String ErrMsg = String.format("L'user con numeroRegistrazione %s non è stato trovato!", registrationNumber);

            log.warning(ErrMsg);

            throw new ChangeSetPersister.NotFoundException();
        }

        return new ResponseEntity<UserDto>(user, HttpStatus.OK);
    }

    }

dto类

@Data
public class UserDto {

    private Long userId;

    private LocalDateTime createdDate;

    private Long number;

    private LocalDateTime modifiedDate;

    private String birthPlace;

    private Date birthDay;

    private Long canNominate;

    private String email;

    private String firstName;

    private String fiscalCode;

    private Date hiringDate;

    private String lastName;

    private String matricola;

    private String position;

    private String registrationNumber;

    private Long replaced;

    private Date terminationDate;

    private String userStatus;

    private Role applicationRoleID;

    private Company companyID;

    private Direction directions ;

    private Levels levelID;

    private User referentID;

    private Role role;

存储库类

public interface UserRepository extends PagingAndSortingRepository<User, Long> {

    @Query(value = "SELECT * FROM USERS WHERE REGISTRATION_NUMBER LIKE :registrationNumber", nativeQuery = true)
    List<User> findByRegistrationNumberLike(@Param("registrationNumber") String registrationNumber);

    User findByRegistrationNumber(String registrationNumber);

}

服务接口和serviceImpl
一个
和模型Map配置

@Configuration
public class ModelMapConfig {

    @Bean
    public ModelMapper modelMapper(){

        return new ModelMapper();
    }
}
qnzebej0

qnzebej01#

您的控制器中有一个打字错误:

//...
@GetMapping(value = "/cerca/{registration_number}", produces = "application/json")
    public ResponseEntity<UserDto> listUserByRegistrationNumber(@PathVariable("registration_Number") String registrationNumber)
//...

注:@PathVariable("registration_Number")一次拼写为大写“N”,一次拼写为小写“n”:@GetMapping(value = "/cerca/{registration_number}"
两者必须相同。

nukf8bse

nukf8bse2#

您的Map为:

/cerca/{registration_number}

因此,您必须像这样调用微服务:

http://localhost:8080/cerca/<a valid registration number>

相关问题