#spring doesnt see my repo class as a bean

31 messages · Page 1 of 1 (latest)

silent tusk
#

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";
    }
}
``` and a repo class:
```java
@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.

and the thing is that i have all the needed annotations. can smb take a look? thx

solemn inletBOT
#

This post has been reserved for your question.

Hey @silent tusk! 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.

signal charm
#

What's the package where the main method resides?

#

Also your repo is wrong

#

You're missing a distance parameter

silent tusk
signal charm
#

That should work. Hmm

silent tusk
silent tusk
signal charm
#

No you shouldn't

#

Show me the application class

silent tusk
signal charm
#

That's fine

#

Is there anything else in your log

#

Because that repository is broken and might be why it's not found

signal charm
#

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

silent tusk
silent tusk
signal charm
#

Yeah it highlights it for you

silent tusk
# signal charm Yeah it highlights it for you

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

do i need to add smth more?

signal charm
#

Don't have to add the last one

#

Just the first 3 is fine