春季启动MVC:春季启动2.1.4无法识别RequestMapping

时间:2019-04-23 13:03:22

标签: java spring-boot spring-mvc thymeleaf

有人可以回答这个愚蠢的问题-如何在Spring Boot版本2.1.4中配置Thymeleaf吗?

我已经声明了正确的依赖项:

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
    </parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

也是配置:

@SpringBootApplication
@ComponentScan("org.mystuff.myproj")
@EnableAutoConfiguration
public class Init extends SpringBootServletInitializer{

控制器看上去很普通:

@Controller
@RequestMapping("/a")
public class IndexController {
    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

    @PostConstruct
    private void test() {
        logger.info("********************************************************************");
    }

    @RequestMapping("/")
    private String index() {
        return "index2";
    }

我确实看到@Controller bean被启动(“ ***** ...”),但是当我尝试在日志中找到“映射”或至少相关的东西时,我发现的唯一东西是:

2019-04-23 15:55:15 WARN  [localhost-startStop-1] JpaBaseConfiguration$JpaWebConfiguration$JpaWebMvcConfiguration.openEntityManagerInViewInterceptor: spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning

2019-04-23 15:55:16 INFO  [localhost-startStop-1] WelcomePageHandlerMapping.<init>: Adding welcome page: ServletContext resource [/index.html]

我无法找到“问题已改变”的答案。

过了一会儿,我意识到在使用8.5时,Spring Boot 2.1.4需要TomCat 9。

此后,我开始取得进展,但Thymeleaf仍然无法正常工作,并且/ templates具有index.html,则使用默认的解析器,该解析器将忽略Thymeleaf的“碎片”和内容(加载方式类似于常规html页)。

0 个答案:

没有答案