Springboot can’t locate my com.example.domain.User.java

I’m starting my first springboot project and all was okay untill I found this issue:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘controllerREST’: Unsatisfied dependency expressed through field ‘userDao’: Error creating bean with name ‘IUserDao’ defined in com.example.dao.IUserDao defined in @EnableJpaRepositories declared on WeatherStartingAppApplication: Not a managed type: class com.example.domain.User

I believe there’s something wrong with my folders structure:

packages

This is the main class:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories(basePackages = "com.example.dao")
@EntityScan(basePackages = "com.example.domain")
@ComponentScan(basePackages = "com.example")
@SpringBootApplication
public class WeatherStartingAppApplication {
public static void main(String[] args) {
SpringApplication.run(WeatherStartingAppApplication.class, args);
}
}
</code>
<code>package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.ComponentScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @EnableJpaRepositories(basePackages = "com.example.dao") @EntityScan(basePackages = "com.example.domain") @ComponentScan(basePackages = "com.example") @SpringBootApplication public class WeatherStartingAppApplication { public static void main(String[] args) { SpringApplication.run(WeatherStartingAppApplication.class, args); } } </code>
package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories(basePackages = "com.example.dao")
@EntityScan(basePackages = "com.example.domain")
@ComponentScan(basePackages = "com.example")

@SpringBootApplication
public class WeatherStartingAppApplication {
    public static void main(String[] args) {
        SpringApplication.run(WeatherStartingAppApplication.class, args);
    }
}

ControllerREST:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.example.controller;
import com.example.domain.User;
import com.example.dao.IUserDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
@Slf4j
public class ControllerREST {
@Autowired
private IUserDao userDao;
@GetMapping("/")
public String index(Model model){
Iterable<User> users = userDao.findAll();
model.addAttribute("users", users);
return "index";
}
}
</code>
<code>package com.example.controller; import com.example.domain.User; import com.example.dao.IUserDao; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller @Slf4j public class ControllerREST { @Autowired private IUserDao userDao; @GetMapping("/") public String index(Model model){ Iterable<User> users = userDao.findAll(); model.addAttribute("users", users); return "index"; } } </code>
package com.example.controller;

import com.example.domain.User;
import com.example.dao.IUserDao;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
@Slf4j
public class ControllerREST {

    @Autowired
    private IUserDao userDao;

    @GetMapping("/")
    public String index(Model model){   
        Iterable<User> users = userDao.findAll();
        model.addAttribute("users", users);
        return "index";
    }
}

IUserDao:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.example.dao;
import com.example.domain.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface IUserDao extends CrudRepository<User, Long> {
}
</code>
<code>package com.example.dao; import com.example.domain.User; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository public interface IUserDao extends CrudRepository<User, Long> { } </code>
package com.example.dao;

import com.example.domain.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository

public interface IUserDao extends CrudRepository<User, Long> {

}

User:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.example.domain;
import java.io.Serializable;
import javax.persistence.*;
import lombok.Data;
@Data
@Entity
@Table(name = "user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private int dni;
private String name;
private String surname;
private String mail;
public User() {
// Default constructor required by JPA
}
public User(int dni, String name, String surname, String mail) {
this.dni = dni;
this.name = name;
this.surname = surname;
this.mail = mail;
}
@Override
public String toString() {
return "{" + dni + ' ' + name + ' ' + surname + ' ' + mail + "}";
}
}
</code>
<code>package com.example.domain; import java.io.Serializable; import javax.persistence.*; import lombok.Data; @Data @Entity @Table(name = "user") public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private int dni; private String name; private String surname; private String mail; public User() { // Default constructor required by JPA } public User(int dni, String name, String surname, String mail) { this.dni = dni; this.name = name; this.surname = surname; this.mail = mail; } @Override public String toString() { return "{" + dni + ' ' + name + ' ' + surname + ' ' + mail + "}"; } } </code>
package com.example.domain;

import java.io.Serializable;
import javax.persistence.*;
import lombok.Data;

@Data
@Entity
@Table(name = "user")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private int dni;
    private String name;
    private String surname;
    private String mail;

    public User() {
        // Default constructor required by JPA
    }

    public User(int dni, String name, String surname, String mail) {
        this.dni = dni;
        this.name = name;
        this.surname = surname;
        this.mail = mail;
    }

    @Override
    public String toString() {
        return "{" + dni + ' ' + name + ' ' + surname + ' ' + mail + "}";
    }
}

The pom file is okay, all dependencies needed are there, I’ve installed all requirements.

New contributor

tomas 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