小编Pra*_*thu的帖子

如何在同一个 Spring Boot 项目中同时使用 thymeleaf 和 jsp

我可以访问 templates 文件夹下的文件,但无法访问 jsp 文件。如果我删除 thymeleaf 依赖项,我就可以访问 jsp 文件,但我想使用 spring boot 访问 thymeleaf html 文件和 jsp 文件。

以下是我在 application.properties 和 pom.xml 中的配置

Spring 视图解析器设置

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
Run Code Online (Sandbox Code Playgroud)
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

下面是错误,当我尝试访问 jsp 文件时

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "todo-form", template might not exist or might not be accessible by any of the configured Template Resolvers spring
Run Code Online (Sandbox Code Playgroud)

我的视图文件夹结构

在此输入图像描述

java jsp thymeleaf spring-boot spring-thymeleaf

7
推荐指数
1
解决办法
3076
查看次数

Mockito thenReturn 总是 null ,Spring-Boot + Junit5 + Mockito

我正在尝试实现 Mockito 来测试特定方法,但似乎.thenReturn(...)总是返回一个null对象,而不是我想要的:

我正在使用mockito 2.22.0和Junit-5以及spring-boot 2.0.4.RELEASE

用户resultUser=userService.save(userDto); 上面的行总是返回空指针异常。不知道为什么 resultUser 总是返回 null,

我的测试课

 @SpringBootTest
    public class UserServiceTests {
    
    @InjectMocks
    private UserService userService =new UserServiceImpl();
    
    @Mock
    private UserRepository userRepository;
    
    @Mock
    BCryptPasswordEncoder passwordEncoder;
    
    @BeforeEach
    void setUp() throws Exception{
        MockitoAnnotations.initMocks(this);
        
    }
    
    @DisplayName("Test saveRegistrationTest method making call to Repository")
    @Test
    public void saveRegistrationTest() {
        
        User user =new User();
        user.setFirstName("TestFN");
        user.setLastName("TestLN");
        user.setEmail("test@test.com");
        user.setPassword("7asdf7asdfi");
        
        User testUser =new User();
        testUser.setFirstName("TestFN");
        
        UserRegistrationDto userDto = new UserRegistrationDto();
        userDto.setFirstName("TestFN");
        
        when(userRepository.save(testUser )).thenReturn(user);
        
        **User resultUser=userService.save(userDto);**
        
        String firstName=(userService.save(userDto)).getFirstName();
        String lastName=(userService.save(userDto)).getLastName(); …
Run Code Online (Sandbox Code Playgroud)

java mockito spring-boot junit5

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

标签 统计

java ×2

spring-boot ×2

jsp ×1

junit5 ×1

mockito ×1

spring-thymeleaf ×1

thymeleaf ×1