Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean

Having a run error in VS code

Error starting ApplicationContext. To display the condition evaluation report re-run your application with ‘debug’ enabled.
2024-05-04T20:04:39.029-07:00 ERROR 27384 — [goblinhorde] [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘characterController’: Unsatisfied dependency expressed through field ‘cService’: Error creating bean with name ‘characterService’: Unsatisfied dependency expressed through field ‘cRepo’: Error creating bean with name ‘characterRepository’ defined in com.goblinhorde.goblinhorde.repositories.CharacterRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Not a managed type: class com.goblinhorde.goblinhorde.models.Characters
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:787) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:767) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:508) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1419) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.6.jar:6.1.6]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962) ~[spring-context-6.1.6.jar:6.1.6]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) ~[spring-context-6.1.6.jar:6.1.6]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.5.jar:3.2.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.2.5.jar:3.2.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.2.5.jar:3.2.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) ~[spring-boot-3.2.5.jar:3.2.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.2.5.jar:3.2.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.2.5.jar:3.2.5]
at com.goblinhorde.goblinhorde.GoblinhordeApplication.main(GoblinhordeApplication.java:11) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.2.5.jar:3.2.5]

CharacterController

package com.goblinhorde.goblinhorde.controllers;

import java.util.List;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.goblinhorde.goblinhorde.models.Characters;
import com.goblinhorde.goblinhorde.models.Store;
import com.goblinhorde.goblinhorde.services.CharacterService;
import com.goblinhorde.goblinhorde.services.StoreService;
import com.goblinhorde.goblinhorde.services.UserService;

@Controller
public class CharacterController {
    
    @Autowired
    private CharacterService cService;
    
    @Autowired
    private UserService uService;
    
    @Autowired
    private StoreService sService;

    @GetMapping("/home")
    public String dashboard(Model viewModel, HttpSession session) {
        Long userId = (Long)session.getAttribute("user_id");
        if(userId == null)
            return"redirect:/";
        
        List<Characters> characters = this.cService.getCharacter();
        viewModel.addAttribute("user", this.uService.findById(userId));
        viewModel.addAttribute("characters", characters);
        return "dashboard.jsp";
    }
    
    // create new Character
    
    @GetMapping("/new")
    private String newCharacter(@ModelAttribute("character") Characters character, HttpSession session, Model viewModel) {
        Long userId = (Long)session.getAttribute("user_id");
        if(userId == null)
            return"redirect:/";
        viewModel.addAttribute("user", this.uService.findById(userId));
        return "newcharacter.jsp";
    }
    
    @PostMapping("/new")
    private String create(@Valid @ModelAttribute("character") Characters character, HttpSession session, BindingResult result, Model viewModel) {
        if(result.hasErrors()) {
            Long userId = (Long)session.getAttribute("user_id");
            viewModel.addAttribute("user", this.uService.findById(userId));
            return "newcharacter.jsp";
        }
            this.cService.create(character);
            return "redirect:/home";
    }
    
    // delete character
    
    @GetMapping("/{id}/delete")
    public String delete(@PathVariable("id") Long id) {
        this.cService.delete(id);
        return "redirect:/home";
    }
    
    // update character name, strength, class
    
    @GetMapping("/{id}")
    public String edit(@PathVariable("id") Long id, HttpSession session, Model viewModel) {
        Long userId = (Long)session.getAttribute("user_id");
        if(userId == null) {
            return "redirect:/";
        } else {
            Characters character = this.cService.findById(id);
            viewModel.addAttribute("character", character);
            viewModel.addAttribute("user", this.uService.findById(userId));
            return "edit.jsp";
        }
    }
    
    @RequestMapping(value = "/{id}", method=RequestMethod.PUT)
    public String update(@Valid @RequestParam("name") String name, @RequestParam("strengthScore") int strengthScore, @RequestParam("charClass") String charClass, @RequestParam("id") Long charId) {
            cService.update(charId, name, charClass, strengthScore);
            return "redirect:/home";
    }
    
    // update character money
    
    @GetMapping("/{id}/coin")
    public String editCoin(@PathVariable("id") Long id, HttpSession session, Model viewModel) {
        Long userId = (Long)session.getAttribute("user_id");
        if(userId == null) {
            return "redirect:/";
        } else {
            Characters character = this.cService.findById(id);
            viewModel.addAttribute("character", character);
            viewModel.addAttribute("user", this.uService.findById(userId));
            return "editcoin.jsp";
        }
    }
    
    @RequestMapping(value = "/{id}/coin", method=RequestMethod.PUT)
    public String updateNew(@Valid @RequestParam("gp") int gp, @RequestParam("sp") int sp, @RequestParam("cp") int cp, @RequestParam("id") Long charId) {
        cService.updateCoin(charId, gp, sp, cp);
        return "redirect:/character/{id}";
    }
    
    // view character
    
    @GetMapping("/character/{id}")
    public String show(@PathVariable("id") Long id, Model viewModel, HttpSession session) {
        Long userId = (Long)session.getAttribute("user_id");
        if(userId == null)
            return"redirect:/";
        
        List<Store> stores = this.sService.getStore();
        viewModel.addAttribute("stores", stores);
        viewModel.addAttribute("character", cService.getOneCharacter(id));
        viewModel.addAttribute("user_id", this.uService.findById(userId));
        return "view.jsp";
        }
    
    // add item to inventory from shop
    
    @GetMapping("/add/{charId}/{itemId}")
    public String add(@PathVariable("charId") Long charId, @PathVariable("itemId") Long itemId, HttpSession session, Model viewModel, String keyword) {
        Long userId = (Long)session.getAttribute("user_id");
        Store characterItems = this.sService.findById(itemId);
        Characters inventories = this.cService.getOneCharacter(charId);
        List<Store> stores = this.sService.getStore();
        String result = this.cService.addItem(characterItems, inventories);
        if(keyword != null) {
            viewModel.addAttribute("stores", sService.findByKeyword(keyword));
        }
        else {
        viewModel.addAttribute("stores", stores);
        }
        viewModel.addAttribute("characters", cService.getOneCharacter(charId));
        viewModel.addAttribute("buyResult", result);
        viewModel.addAttribute("user", this.uService.findById(userId));
        return "redirect:/shop/{charId}";
    }
    
    // remove item from inventory
    
    @GetMapping("/remove/{charId}/{itemId}")
    public String add(@PathVariable("charId") Long charId, @PathVariable("itemId") Long itemId, HttpSession session) {
        Store characterItems = this.sService.findById(itemId);
        Characters inventories = this.cService.getOneCharacter(charId);
        this.cService.removeItem(characterItems, inventories);
        return "redirect:/shop/{charId}";

CharacterService

package com.goblinhorde.goblinhorde.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goblinhorde.goblinhorde.models.Characters;
import com.goblinhorde.goblinhorde.models.Store;
import com.goblinhorde.goblinhorde.repositories.CharacterRepository;

@Service
public class CharacterService {
    
    @Autowired
    private CharacterRepository cRepo;
    
    
    public List<Characters> getCharacter() {
        return this.cRepo.findAll();
    }
    
    public Characters findById(Long id) {
        return this.cRepo.findById(id).orElse(null);
    }
    
    public Characters getOneCharacter(Long id) {
        Characters character = this.cRepo.findById(id).orElse(null);
        return character;
    }
    
    // create character
    
    public Characters create(Characters character) {
        int carryCapacity = character.getCarryCapacity();
        character.setCarryCapacity(carryCapacity);
        return this.cRepo.save(character);
    }
    
    // update character
    
    public Characters update(Long id, String name, String charClass, int strengthScore ) {
        Characters updatedCharacter = this.getOneCharacter(id);
        updatedCharacter.setName(name);
        updatedCharacter.setCharClass(charClass);
        updatedCharacter.setStrengthScore(strengthScore);
        int carryCapacity = updatedCharacter.getCarryCapacity();
        updatedCharacter.setCarryCapacity(carryCapacity);
        return this.cRepo.save(updatedCharacter);
    }
    
    // update character money
    
    public void updateCoin(Long id, int gp, int sp, int cp) {
        Characters updatedCharacter = this.getOneCharacter(id);
        updatedCharacter.setGp(gp);
        updatedCharacter.setSp(sp);
        updatedCharacter.setCp(cp);
        cRepo.save(updatedCharacter);
    }
    
    // delete character
    
    public void delete(Long id) {
        this.cRepo.deleteById(id);
    }
    
    //Add item
        public String addItem(Store store, Characters character) {
            if(store.getPriceGP() > character.getGp()) {
                return "Not enough gold.";
            }
            int weight = character.getCarryCapacity() - store.getWeight();
            if(weight <= 0) {
                return "Not enough space.";
            }
            character.updateCarryCapacity(weight);
            int gold = character.getGp() - store.getPriceGP();
            character.setGp(gold);
            List<Store> inventories = character.getInventories();
            inventories.add(store);
            this.cRepo.save(character);
            return "Item purchased.";
        }
        
        // Remove item

        public void removeItem(Store store, Characters character) {
            int weight = character.getCarryCapacity() + store.getWeight();
            int gold = character.getGp() + store.getPriceGP();
            character.updateCarryCapacity(weight);
            character.setGp(gold);
            character.getInventories().remove(store);
            this.cRepo.save(character);
        }
}

CharacterRepository

package com.goblinhorde.goblinhorde.repositories;

import java.util.List;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.goblinhorde.goblinhorde.models.Characters;
import com.goblinhorde.goblinhorde.models.User;

@Repository
public interface CharacterRepository extends CrudRepository<Characters, Long> {
    
    @Override
    List<Characters> findAll();
    List<Characters> findByUser(User user);
    List<Characters> findByStrengthScore(int strengthScore);
    List<Characters> findByName(String name);
    List<Characters> findByCharClass(String charClass);
    Characters findByGp(int gp);
    Characters findBySp(int sp);
    Characters findByCp(int cp);
    Characters findOneById(Long id);
}

**
POM.XML**

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.goblinhorde.goblinhorde</groupId>
    <artifactId>goblinhorde</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>goblinhorde</name>
    <description>Goblin Horde - TTRPG Shop Generator</description>
    <properties>
        <java.version>22</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.30.2-GA</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mindrot</groupId>
            <artifactId>jbcrypt</artifactId>
            <version>0.4</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>8.0.30</version>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>3.2.5</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

not really sure what I am missing

New contributor

Garrett Crawford is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật