Spring In Action 21.3示例代码出现Could not find artifact :thymeleaf-spring4:jar: in local

在尝试使用 Spring Boot CLI 和 Groovy 编写控制器时,遇到 `Could not find artifact :thymeleaf-spring4:jar: in local` 的错误。该错误发生在依赖解析阶段,由于本地仓库找不到 thymeleaf-spring4 的 jar 包。解决办法是将 `@Grab("thymeleaf-spring4")` 替换为 `@Grab("spring-boot-starter-thymeleaf")`,这样可以正确引入 thymeleaf 模板引擎。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:

 springboot-CLI-2.0.1.RELEASE

控制器groovy类信息:

@Grab("thymeleaf-spring4")
@Controller
@RequestMapping("/")
class ContactController {

    @Autowired
    ContactRepository contactRepo

    @RequestMapping(method=RequestMethod.GET)
    String home(Map<String,Object> model) {
        List<Contact> contacts = contactRepo.findAll()
        model.putAll([contacts: contacts])
        "home"
    }

    @RequestMapping(method=RequestMethod.POST)
    String submit(Contact contact) {
        contactRepo.save(contact)
        "redirect:/"
    }

}

具体错误信息:

D:\SpringBootCLI -GroovyProject\contacts>spring run *.groovy
Resolving dependencies...
startup failed:
General error during conversion: org.eclipse.aether.resolution.DependencyResolut
ionException: Could not find artifact :thymeleaf-spring4:jar: in local (file:/D:
/SpringBootCLI%20-GroovyProject/contacts/repository)

org.springframework.boot.cli.co

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值