Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导rest控制器未映射_Java_Spring_Rest_Spring Boot - Fatal编程技术网

Java Spring引导rest控制器未映射

Java Spring引导rest控制器未映射,java,spring,rest,spring-boot,Java,Spring,Rest,Spring Boot,我正在构建简单的testrestapi,基本上当调用/testing时,它将创建一个日志对象并将其发送到另一个api(独立于项目及其运行)。但无论何时去/测试,都不能通过控制器。奇怪的是,它以前是工作的。我在application.properties中包含了logging.level.org.springframework.web=DEBUG。下面是日志和我的源文件 2019-01-17 15:53:17.475 INFO 7981 --- [ main] m.c.c.s

我正在构建简单的testrestapi,基本上当调用/testing时,它将创建一个日志对象并将其发送到另一个api(独立于项目及其运行)。但无论何时去/测试,都不能通过控制器。奇怪的是,它以前是工作的。我在application.properties中包含了logging.level.org.springframework.web=DEBUG。下面是日志和我的源文件

2019-01-17 15:53:17.475  INFO 7981 --- [           main] m.c.c.s.t.TestProjectApplication         : No active profile set, falling back to default profiles: default
2019-01-17 15:53:17.975  INFO 7981 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=34ed4a34-6e50-3cb5-ac90-9466e43258a8
2019-01-17 15:53:18.025  INFO 7981 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$dcc06eb1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-17 15:53:18.286  INFO 7981 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9010 (http)
2019-01-17 15:53:18.315  INFO 7981 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-01-17 15:53:18.315  INFO 7981 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-01-17 15:53:18.320  INFO 7981 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
2019-01-17 15:53:18.459  INFO 7981 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-01-17 15:53:18.459 DEBUG 7981 --- [           main] o.s.web.context.ContextLoader            : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2019-01-17 15:53:18.459  INFO 7981 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 975 ms
2019-01-17 15:53:18.514  WARN 7981 --- [           main] o.s.c.n.a.ArchaiusAutoConfiguration      : No spring.application.name found, defaulting to 'application'
2019-01-17 15:53:18.516  WARN 7981 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2019-01-17 15:53:18.516  INFO 7981 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-01-17 15:53:18.518  WARN 7981 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2019-01-17 15:53:18.518  INFO 7981 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-01-17 15:53:18.573 DEBUG 7981 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/**/favicon.ico] in 'faviconHandlerMapping'
2019-01-17 15:53:18.669  INFO 7981 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-01-17 15:53:18.676 DEBUG 7981 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2019-01-17 15:53:18.705 DEBUG 7981 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2019-01-17 15:53:18.713 DEBUG 7981 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2019-01-17 15:53:18.721 DEBUG 7981 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2019-01-17 15:53:18.871  INFO 7981 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9010 (http) with context path ''
2019-01-17 15:53:18.874  INFO 7981 --- [           main] m.c.c.s.t.TestProjectApplication         : Started TestProjectApplication in 1.976 seconds (JVM running for 2.504)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2019-01-17 15:53:26.870  INFO 7981 --- [nio-9010-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-01-17 15:53:26.870  INFO 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-01-17 15:53:26.870 DEBUG 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2019-01-17 15:53:26.875 DEBUG 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2019-01-17 15:53:26.875  INFO 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 5 ms
2019-01-17 15:53:26.881 DEBUG 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : GET "/testing", parameters={}
2019-01-17 15:53:26.886 DEBUG 7981 --- [nio-9010-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2019-01-17 15:53:26.887 DEBUG 7981 --- [nio-9010-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2019-01-17 15:53:26.887 DEBUG 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2019-01-17 15:53:26.890 DEBUG 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2019-01-17 15:53:26.894 DEBUG 7981 --- [nio-9010-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-01-17 15:53:26.923 DEBUG 7981 --- [nio-9010-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
2019-01-17 15:53:26.929 DEBUG 7981 --- [nio-9010-exec-1] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404
TestProjectApplication.java

package my.com.cybersolution.skb.testproject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import my.com.cybersolution.skb.elogginglibrary.filter.EloggingFilter;

@SpringBootApplication
@ComponentScan(basePackages = {"my.com.cybersolution.skb.elogginglibrary.filter.EloggingFilter"})
public class TestProjectApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestProjectApplication.class, args);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    }

    @Bean
    public FilterRegistrationBean<EloggingFilter> loggingFilter(){
        FilterRegistrationBean<EloggingFilter> registrationBean = new FilterRegistrationBean<>();

        registrationBean.setFilter(new EloggingFilter());
        //registrationBean.addUrlPatterns("/users/*");

        return registrationBean;    
    }

}
TestClient.java

package my.com.cybersolution.skb.testproject.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import my.com.cybersolution.skb.testproject.object.LoggingObject;

@FeignClient(name = "eloggingClient", url = "localhost:9090")
@Component
public interface TestClient {
    @PostMapping("/logging")
    public boolean sendMessage(@RequestBody LoggingObject logging);
}

您的
RestController
未被调用,因为您将
@ComponentScan
注释与固定的
basePackages
一起添加到
TestProjectApplication.java
中,它不包括控制器中的包。这意味着Spring将永远不会扫描您的
控制器
包,并且它无法注册任何端点


要解决这个问题,只需从您的
TestProjectApplication.java
中删除
@ComponentScan
,默认行为是扫描所有包,这样您的控制器就可以再次访问了。

非常感谢,我真的被这个问题困住了。我无法删除组件扫描,因为我需要它来扫描导入的外部库。所以我添加了这个
@ComponentScan(basePackages={“my.com.cybersolution.skb.eloginglibrary.filter.elogingfilter”,“my.com.cybersolution.skb.testproject”})
package my.com.cybersolution.skb.testproject.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import my.com.cybersolution.skb.testproject.object.LoggingObject;

@FeignClient(name = "eloggingClient", url = "localhost:9090")
@Component
public interface TestClient {
    @PostMapping("/logging")
    public boolean sendMessage(@RequestBody LoggingObject logging);
}