Pessoal começou a dar um problema de dependencias depois que eu entrei na parte de H2, estranho porque todas as classes estão anotadas, alguem poderia dar um help? org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'topicoController' defined in file [/Users/ramaro/Documents/repositorio/Kotlin/target/classes/br/com/alura/forum/controller/TopicoController.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'topicoService' defined in file [/Users/ramaro/Documents/repositorio/Kotlin/target/classes/br/com/alura/forum/service/TopicoService.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'topicoRepository' defined in br.com.alura.forum.repository.TopicoRepository defined in @EnableJpaRepositories declared on ForumApplication: Not a managed type: class br.com.alura.forum.model.Topico
Controller
@RestController
@RequestMapping("/topicos")
class TopicoController(private val topicosService: TopicoService) {
@GetMapping
fun listar(): List<TopicoView> {
return topicosService.listar()
}
@GetMapping("/{id}")
fun buscarPorId(@PathVariable id: Long): TopicoView {
return topicosService.buscarPorId(id)
}
@PostMapping
fun cadastrar(@RequestBody @Valid form: NovoTopicoForm,
uriBuilder: UriComponentsBuilder
): ResponseEntity<TopicoView> {
val topicoView = topicosService.cadastrar(form)
val uri = uriBuilder.path("/topicos/{topicoView.id}").build().toUri()
return ResponseEntity.created(uri).body(topicoView)
}
@PutMapping
fun atualizar(@RequestBody @Valid form: AtualizacaoTopicoForm): ResponseEntity<TopicoView> {
val topicoView = topicosService.atualizar(form)
return ResponseEntity.ok(topicoView)
}
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun deletar(@PathVariable id: Long) {
topicosService.deletar(id)
}
}
Service
package br.com.alura.forum.service
import br.com.alura.forum.dto.AtualizacaoTopicoForm
import br.com.alura.forum.dto.NovoTopicoForm
import br.com.alura.forum.dto.TopicoView
import br.com.alura.forum.exception.NotFoundException
import br.com.alura.forum.mapper.TopicoFormMapper
import br.com.alura.forum.mapper.TopicoViewMapper
import br.com.alura.forum.repository.TopicoRepository
import org.springframework.stereotype.Service
import java.util.stream.Collectors
@Service
class TopicoService(
private val repository: TopicoRepository,
private val topicoViewMapper: TopicoViewMapper,
private val topicoFormMapper: TopicoFormMapper,
) {
private val notFoundMessage: String = "Topico nao encontrado!"
fun listar(): List<TopicoView> {
return repository.findAll().stream().map {
t -> topicoViewMapper.map(t)
}.collect(Collectors.toList())
}
fun buscarPorId(id: Long): TopicoView {
val topico = repository.findById(id)
.orElseThrow { NotFoundException(notFoundMessage) }
return topicoViewMapper.map(topico)
}
fun cadastrar(form: NovoTopicoForm): TopicoView {
val topico = topicoFormMapper.map(form)
repository.save(topico)
return topicoViewMapper.map(topico)
}
fun atualizar(form: AtualizacaoTopicoForm): TopicoView {
val topico = repository.findById(form.id).orElseThrow { NotFoundException(notFoundMessage) }
topico.titulo = form.titulo
topico.mensagem = form.mensagem
return topicoViewMapper.map(topico)
}
fun deletar(id: Long) {
repository.deleteById(id)
}
}
Repository
package br.com.alura.forum.repository
import br.com.alura.forum.model.Curso
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface CursoRepository: JpaRepository<Curso, Long> {
}