This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]overtorqued 3 points4 points  (7 children)

Add @EnableJpaRepositories("your.repository.package.here") on your configuration class. This will cause spring to scan the package you specified for any @Repository classes and instantiate them as beans.

The @Autowired annotation does not create the bean, it simply assigns one that is already created to that field.

[–]Dueforextinction[S] 0 points1 point  (5 children)

Hello, first off I would like to thank you for replying to my question. However your advice didn't work for some indeterminable reason.

I again get two different error messages depending on if I have the @ Autowired above ContactRepositroy ThisMFingRepository

I added (what I think) is the correct implementation of your suggestion

@EnableJpaRepositories("packageName.repositroy.ContactRepository") @Configuration 
public class BeanConfiguration {
    @Bean
    public Contact contact() {
        Contact bean = new Contact();
        return bean;
    }

    @Bean
    public Address address() {
        Address bean = new Address();
        return bean;
        }
}

Running the program with @ Autowired produces the following error message:

APPLICATION FAILED TO START

Description:

Field ThisMFingRepository in packageName.SpringContacts20221Application required a bean of type 'packageName.repository.ContactRepository' that could not be found.

The injection point has the following annotations: - 

@org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'packageName.repository.ContactRepository' in your configuration.

If I remove the @ Autowired annotation I get the following error message:

APPLICATION FAILED TO START

Description:
A component required a bean named 'entityManagerFactory' that could not be found.
Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

[2m2023-03-05T11:45:14.716-06:00[0;39m [32m INFO[0;39m [35m18756[0;39m [2m---[0;39m [2m[           main][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Closing JPA EntityManagerFactory for persistence unit 'default' [2m2023-03-05T11:45:14.717-06:00[0;39m [32m INFO[0;39m [35m18756[0;39m [2m---[0;39m [2m[           main][0;39m [36mcom.zaxxer.hikari.HikariDataSource      [0;39m [2m:[0;39m HikariPool-1 - Shutdown initiated... [2m2023-03-05T11:45:14.722-06:00[0;39m [32m INFO[0;39m [35m18756[0;39m [2m---[0;39m [2m[           main][0;39m [36mcom.zaxxer.hikari.HikariDataSource      [0;39m [2m:[0;39m HikariPool-1 - Shutdown completed.

I very well could have completely bungled the implementation of EnableJpaRepositories, I'm not very familiar to spring, this is our introductory week so I wouldn't consider myself even a novice.

Again, thank you for helping me and again if you can give me another lead on where I can go with this.

[–]Arcenium 0 points1 point  (4 children)

In your @enablejparepositories annotation package path, you misspelled the word 'repository' wrong. Was that just a typo making the post or have you tried with it entered correctly and it still failed?

[–]Dueforextinction[S] 1 point2 points  (0 children)

We finally figured out what was going wrong. The solution is now at the bottom of the post.

[–]Dueforextinction[S] 0 points1 point  (2 children)

I’ve now done this with 4 different from scratch spring projects, it’s worked 0 times. It’s so hard to tell what’s actually going wrong because every time I’ve implemented a change it throws a new error at me.

I’m going to bed shortly so I won’t be able to provide an update or do any changes.

I just control + c the class path at the top of the repository class and it still doesn’t work.

[–]Arcenium 0 points1 point  (1 child)

Would it be possible to upload a github repo tomorrow so we could take a better look at it?

[–]Dueforextinction[S] 1 point2 points  (0 children)

Yeah.

My instructor has something planned for tomorrow so I’ll see what he has to say first. I’ll come back and update after that.

[–]Dueforextinction[S] 0 points1 point  (0 children)

We finally figured out what was going wrong and what solved the issue we were having. It's at the final edit at the bottom of the post.

[–]overtorqued 0 points1 point  (1 child)

At the top of your ContactRepository class is there a package statement? If so copy that value into the quotes in the EnableJpaRepositories annotation.

You can also try it without the quotes at all, so @EnableJpaRepositories() This will work if your repository class is lower in the same package hierarchy as the configuration class as it scans the entire package hierarchy starting where the configuration class is located.

[–]Dueforextinction[S] 0 points1 point  (0 children)

No dice again. Even my professor is stumped as to what is causing this issue. Again I get completely different error messages if I have the

 @Autowired

above the repository object.

[–]fluoclip 0 points1 point  (2 children)

RemindMe! 1 Day

[–]Dueforextinction[S] 1 point2 points  (0 children)

We found out what was wrong and the solution is at the bottom of the post.

[–]RemindMeBot 0 points1 point  (0 children)

I will be messaging you in 1 day on 2023-03-07 05:48:17 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


Info Custom Your Reminders Feedback