@springbootapplication显示annotation type expected

本文介绍了在SpringBoot项目中遇到Annotationtypeexpected错误的原因和解决方案。问题源于类名与关键字冲突,只需简单修改类名即可正常启动。此外,还探讨了避免此类错误的方法,确保项目的顺利运行。

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

问题描述:

已经添加了yml和springboot依赖,在之后标注启动类仍然显示Annotation type expected

错误原因:类名不能与关键字一样,所以将类名修改一下即可。

``` @SpringBootTest //@RunWith:表示启动这个单元测试类(不写单元测试类不能运行),需要传递一个参数,固定为SpringRunner的实例类型 @RunWith(SpringRunner.class) public class ProductPricegroupMateriaServiceTests { // 测试类框架(使用JUnit 5 + Spring Boot Test) @Resource private ProductPricegroupMateriaService productPricegroupMateriaService; @Test public void testSelectByComplexExample() { // 测试复杂查询 /*ProductPricegroupMateriaExample example = new ProductPricegroupMateriaExample(); ProductPricegroupMateriaExample.Criteria criteria = example.createCriteria(); criteria.andCategoryIdEqualTo(1); criteria.andMaterialNameEqualTo(""); criteria.andPriceGroupEqualTo("");*/ List<ProductPricegroupMateria> result = productPricegroupMateriaService.queryByConditions(1,"",""); System.err.println(result); } }```Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@34e9fd99] to prepare test instance [com.ljs.pojectTest.service.ProductPricegroupMateriaServiceTests@76ddd61a] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.ljs.pojectTest.service.ProductPricegroupMateriaServiceTests': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ljs.pojectTest.service.ProductPricegroupMateriaService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
最新发布
04-01
// HeartbeatController.java package com.ruoyi.dataAcquisition.controller; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @RestController @CrossOrigin(origins = "*") @SpringBootApplication(scanBasePackages = "com.ruoyi.dataAcquisition.controller") public class HeartbeatController { private static final ConcurrentHashMap<String, Long> clientStatus = new ConcurrentHashMap<>(); private static final long OFFLINE_THRESHOLD = 90000; @Operation(summary = "心跳上报接口") @GetMapping("/heartbeat") public ResponseEntity<Map<String, Object>> heartbeat( @Parameter(description = "设备唯一标识", required = true) @RequestParam String clientId ) { clientStatus.put(clientId, System.currentTimeMillis()); Map<String, Object> response = new HashMap<>(); response.put("status", "online"); response.put("clientId", clientId); return ResponseEntity.ok(response); } @Operation(summary = "设备状态查询接口") @GetMapping("/client-status") public ResponseEntity<Map<String, Object>> getClientStatus( @Parameter(description = "设备唯一标识", required = true) @RequestParam String clientId ) { Long lastBeat = clientStatus.get(clientId); boolean isOnline = lastBeat != null && (System.currentTimeMillis() - lastBeat) < OFFLINE_THRESHOLD; Map<String, Object> response = new HashMap<>(); response.put("status", isOnline ? "online" : "offline"); response.put("lastHeartbeat", lastBeat); return ResponseEntity.ok(response); } }这是自己创建的包的接口,为什么curl调用报错
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值