弹簧启动控制器未正确扫描

时间:2020-10-05 10:00:00

标签: spring-boot

我肯定在映射方面遇到问题,我在spring boot中创建了一个简单的应用程序,但是映射错误,这是我的代码:

package com.example.demo;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;


@SpringBootApplication
@ComponentScan(basePackages={"com.example"})
public class DemopApplication2 {

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

}


package com.example.demo.jjj;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RequestMapping(value = "/hanoipp")
public class Omp {
    @RequestMapping("/smm")
    String welcome() {
        return "index";
    }
}

,我在模板中有一个简单的html文件,称为index.html,但这不起作用 我的日志文件是:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)

2020-10-05 10:53:07.911  INFO 6380 --- [  restartedMain] com.example.demo.DemopApplication2       : Starting DemopApplication2 on ACER-3DF47200 with PID 6380 (D:\oneDr\OneDrive - OFPPT\Data\training IT\jee\demop\target\classes started by user in D:\oneDr\OneDrive - OFPPT\Data\training IT\jee\demop)
2020-10-05 10:53:07.916  INFO 6380 --- [  restartedMain] com.example.demo.DemopApplication2       : No active profile set, falling back to default profiles: default
2020-10-05 10:53:07.989  INFO 6380 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-10-05 10:53:07.990  INFO 6380 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-10-05 10:53:09.107  INFO 6380 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
2020-10-05 10:53:09.120  INFO 6380 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-10-05 10:53:09.120  INFO 6380 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-10-05 10:53:09.195  INFO 6380 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-10-05 10:53:09.195  INFO 6380 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1205 ms
2020-10-05 10:53:09.412  INFO 6380 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-10-05 10:53:09.597  INFO 6380 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2020-10-05 10:53:09.642  INFO 6380 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8090 (http) with context path ''
2020-10-05 10:53:09.660  INFO 6380 --- [  restartedMain] com.example.demo.DemopApplication2       : Started DemopApplication2 in 2.088 seconds (JVM running for 2.476)
erffffggggggggggggf
2020-10-05 10:53:11.645  INFO 6380 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-10-05 10:53:11.646  INFO 6380 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-10-05 10:53:11.653  INFO 6380 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms

1 个答案:

答案 0 :(得分:0)

静态html文件转到static,而不是template

static中的所有内容都直接传递给客户端。

没有thymeleaf,您没有用于html文件的服务器端解析器。

template目录是经过解析的模板文件,它们产生客户端接收的数据。

当我添加thyeleaf插件时,它工作正常,当我删除它时,deos无法正常工作 Thymeleaf可处理html目录中的template个文件。然后将这些文件解析到服务器端,并将thymeleaf标签/属性转换为html。

如果您有百里香可用并使用普通的html文件,则这些文件将被发送到客户端,而不会被更改。