小编Nex*_*exx的帖子

“Controller”中构造函数的参数 0 需要一个“service”类型的 bean,但无法找到。不起作用:添加注释、组件扫描

我正在尝试在我的项目中使用服务和 DTO(尝试了解它们是什么以及应该如何使用它们)。首先,我只有控制器、模型和存储库。后端按预期工作。然后,我想我应该使用 DTO 和服务将客户端与存储库连接起来。但我的应用程序后来无法运行。

项目结构项目结构

电影控制器:

package movie_API.movie.controllers;

import movie_API.movie.services.MovieService;
import movie_API.movie.services.beans.MovieDTO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Controller
//@RequestMapping("/something") <- if you want a general something before the other resources
public class MovieController {

    private final MovieService movieService;

    public MovieController(MovieService movieService) {
        this.movieService = movieService;
        System.out.println("build controller");
    }

    @GetMapping("/movies")
    public String movies(Model model) {
        System.out.println("before getting in");
        movieService.showMovies(model);
        System.out.println("after getting in");

        return "movie/movies-all";
    }
 }
Run Code Online (Sandbox Code Playgroud)

电影模型 + 相应的构造函数和 getter 和 setter:

package …
Run Code Online (Sandbox Code Playgroud)

java service javabeans dto spring-boot

2
推荐指数
1
解决办法
1万
查看次数

ConfigServletWebServerApplicationContext:嵌套异常是 java.lang.NoClassDefFoundError:使用 Tomcat 10 的 jakarta/servlet/jsp/JspFactory - Spring

我正在尝试从Youtube制作 SpringBoot 教程。但在IntelliJ + Maven中,而不是 Eclipse 中。在 1 小时处,他们添加了 jasper 依赖项,然后运行该程序,它运行良好。

在添加 jasper 依赖项之前,我没有任何错误。添加后,我收到此错误:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoClassDefFoundError: jakarta/servlet/jsp/JspFactory. 
Run Code Online (Sandbox Code Playgroud)

这是我的主要应用程序文件:


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class CoursesWebApp {

    public static void main(String[] args) {
        SpringApplication.run(CoursesWebApp.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

和控制器文件

package com.example.springboot;

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

@Controller
public class CoursesController {

    @RequestMapping("/courses")
    public void coursesDisplay() {
        System.out.println("Welcome to courses!");
        //return …
Run Code Online (Sandbox Code Playgroud)

java jsp maven spring-boot tomcat10

0
推荐指数
1
解决办法
3629
查看次数

标签 统计

java ×2

spring-boot ×2

dto ×1

javabeans ×1

jsp ×1

maven ×1

service ×1

tomcat10 ×1