spring doesnt see my repo class as a bean

hey guys. so i have my service class:
@Service
public class ItemService {
private ItemRepository itemRepository;
public ItemService(ItemRepository itemRepository) {
this.itemRepository = itemRepository;
}
public String getItemsByDistanceAndSeason(double distance,String season) {
//call repo, etc
return "Get items";
}
}
@Service
public class ItemService {
private ItemRepository itemRepository;
public ItemService(ItemRepository itemRepository) {
this.itemRepository = itemRepository;
}
public String getItemsByDistanceAndSeason(double distance,String season) {
//call repo, etc
return "Get items";
}
}
and a repo class:
@Repository
public interface ItemRepository extends CrudRepository<Item,Long> {
public List<Item> getAllByDistanceAndSeason(String season);
}
@Repository
public interface ItemRepository extends CrudRepository<Item,Long> {
public List<Item> getAllByDistanceAndSeason(String season);
}
but when i start my app, i get an error:
Description:

Parameter 0 of constructor in lt.brilingas.tieto.service.ItemService required a bean of type 'lt.brilingas.tieto.repository.ItemRepository' that could not be found.


Action:

Consider defining a bean of type 'lt.brilingas.tieto.repository.ItemRepository' in your configuration.
Description:

Parameter 0 of constructor in lt.brilingas.tieto.service.ItemService required a bean of type 'lt.brilingas.tieto.repository.ItemRepository' that could not be found.


Action:

Consider defining a bean of type 'lt.brilingas.tieto.repository.ItemRepository' in your configuration.
and the thing is that i have all the needed annotations. can smb take a look? thx
16 Replies
JavaBot
JavaBot11mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
tjoener
tjoener11mo ago
What's the package where the main method resides? Also your repo is wrong You're missing a distance parameter
bambyzas
bambyzasOP11mo ago
its lt.brilingas.tieto
No description
tjoener
tjoener11mo ago
That should work. Hmm
bambyzas
bambyzasOP11mo ago
whats a distance param? i tried googling but found nothing specific do i need to have a config class of some sort?
tjoener
tjoener11mo ago
No you shouldn't Show me the application class
bambyzas
bambyzasOP11mo ago
No description
tjoener
tjoener11mo ago
That's fine Is there anything else in your log Because that repository is broken and might be why it's not found
bambyzas
bambyzasOP11mo ago
all my log https://pastecode.io/s/e8137kjg why it is broken?
tjoener
tjoener11mo ago
You're doing byDistanceAndSeason JPA rules state you need a second parameter then Which ide do you use? Community or pro? List<Item> getAllByDistanceAndSeason(String distance, String season); That's what it should be I use string but use whatever datatype it actually is
bambyzas
bambyzasOP11mo ago
intellij idea pro
bambyzas
bambyzasOP11mo ago
fml. i totally forgot haha. but that also didnt do stuff
No description
tjoener
tjoener11mo ago
Yeah it highlights it for you
bambyzas
bambyzasOP11mo ago
i forgor to config my db in app.properties. i have this
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=p@55word
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=p@55word
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
do i need to add smth more?
tjoener
tjoener11mo ago
Don't have to add the last one Just the first 3 is fine
JavaBot
JavaBot11mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server