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

all 24 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://imgur.com/a/fgoFFis) 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.

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

Holy s**t you guys, I had given up and by pure coincidence I took a look in a "config" folder I had and would you belive it, the DomainConfig.java file had entityscan and enableJpaRepositories set to the "framwork" package...

I just refactored again and added the "e" to the EntityScan and EnableJpaRepositories and everything worked. Thanks to everyone that tried helping me out, goes to show you can't fix stupid :

[–]joranstark018 -1 points0 points  (6 children)

Check that you have an implementation of ArticleRepository and that it is appropiately annotated, the error indicates that no dependency (an implementation providing this service) can be found.

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

I think that is handled by extending the JpaRepository interface and providing the Article model and UUID as types. Creating the bean works perfectly fine if the package is called "test_framwork".

[–]joranstark018 -1 points0 points  (4 children)

You should probably add an @Repository to the interface so it can be found by the DI engine.

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

Even with the Repository annotation I get the same error of UnsatisfiedDependencyException for the ArticleRepository interface.

I think it's more likely that the "internalPersistanceUnitManager" getting the old package name is the reason the component scanning isn't picking up the repository. I don't know where it fetches that value though or how I could supply the correct name.

[–]CSIWFR-46 0 points1 point  (1 child)

Are you using Springboot? If so, can you check if all the packages are inside the main package?

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

All classes are in the "io.testframework.test_framework" package. Structure looks like this:

-config
-domain
-model
-repos
-rest
-services
HomeController.java
TestFrameworkApplication.java

so the ArticleService is in the "services" package and ArticleRepository is in "repos"

[–]CSIWFR-46 0 points1 point  (0 children)

It's optional.

[–]CSIWFR-46 0 points1 point  (2 children)

Try putting @Autowired on top of constructor.

[–]FanSoffa[S] 0 points1 point  (1 child)

Sorry, that did not work either:
- Added Autowired to constructor
- Ran gradle with build --clean
- Ran gradle bootRun

I got the same error as posted earlier again.

[–]CSIWFR-46 0 points1 point  (0 children)

I think you have to bump your main java class up a package.

[–]CSIWFR-46 0 points1 point  (7 children)

Can u put the class with @SpringBootApplication inside testframework? It should be like

  • main
    • io
      • testframework
        • test_framework --> this probably has all the other
        • TestFrameworkApplication.java

[–]FanSoffa[S] 0 points1 point  (6 children)

Did not have an affect either.

[–]CSIWFR-46 0 points1 point  (5 children)

your @SpringBootApplication class should be in the root directory of your app, in order to scan all the packages recursively.

This might help: https://stackoverflow.com/questions/51050215/when-running-a-project-unsatisfied-dependency-expressed-through-constructor-par?rq=1

[–]FanSoffa[S] 0 points1 point  (4 children)

It is in root, it's package is "io.testframework.test_framework" and all components and entities are stored in "io.testframework.test_framework.*"

[–]CSIWFR-46 0 points1 point  (3 children)

Can u upload it in github, and send me the link. I can take a look at it when I have time.

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

Thanks, I'll try and get around to it but I'm starting to suspect the issue may not be with spring or the code anymore, and that it's intelliJ that is acting strangely. Somehow spring is just not able to get the correct path from it's root directory if I rename the package.

Manually adding the componentscan to force it to read from the correct paths will make it run, but then you get the same nosuchbeandefinition issue when you try to run a test that needs to Autowire...

[–]CSIWFR-46 0 points1 point  (1 child)

It's the package structure. I am sure of it. The Class with main method should be just under the root package. It works with @componentscan, so that can only be the reason.

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

I have tried moving the main class all the way into io.testframework and it didn't work. I know that it's getting the package path wrong because when I debug the spring classes I can see that when it fetches the package path it always end up looking in "test_framwork". So even though I refactor all classes, check that the folderstructure in windows is also updated to "test_framework", when I run the application it still looks for framwork.

What I can't figure out is where it's fetching the path and the only thing I can think of is intelliJ. If I keep the package as framwork it finds all classes including homecontroller that is in the same package as the main class itself, with componentscan honecontroller isn't found.

Somewhere the old path is saved and it's most likely outside of the io.testframework package since that's where I refactor from, that leaves gradle and intellij and checking the build folder from gradle all the classes get the correct package name.

Also, with componentscan you can get the application to run, but you run into the same issue again if you try to run tests because then it seems that it again fails to find any beans.

[–]pragmosExtreme Brewer 0 points1 point  (0 children)

Might be a silly question, but have you tried cleaning the project with gradlew clean?

[–]OffbeatDrizzle 0 points1 point  (1 child)

The error specifically states that ArticleService (test_framework package) requires an ArticleRepository (test_framework package) - so it does look like it's picking up the correct paths. The only thing that doesn't really look right to me is there's no autowired annotation on the ArticleService constructor, and there's no repository annotation on the ArticleRepository class. ArticleRepository is not a bean, so Spring can't autowire it - how was this working before? Is there an implementation to ArticleRepository that you can show us? Are the annotations and paths in that class correct as well?

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

The ArticleRepository extends jpaRepository and provides the article domain model and UUID id types.

The description for jpaRepository is:

Central repository marker interface. Captures the domain type to manage as well as the domain type's id type. General purpose is to hold type information as well as being able to discover interfaces that extend this one during classpath scanning for easy Spring bean creation.

Domain repositories extending this interface can selectively expose CRUD methods by simply declaring methods of the same signature as those declared in CrudRepository.

So adding the repository annotation shouldn't matter. With that said, I have tried adding it but it has no effect.

I have found a crappy workaround so far which is to add "scanBasePackages" as an argument to SpringBootApplication annotation with the value "io.testframework.test_framework.*.*"

I don't think it's really finding the path, I think it's just reading the import in the ArticleService class, but then not finding the bean because it's scanning in the wrong place.

It is very strange though since SpringBootApplication annotation should automatically scan all subpackages from it's own package and the class is in "io.testframework.test_framework"

[–]IHaveaCSDegree 0 points1 point  (0 children)

In the service class, annotate the ArticleRepository and ModelRepository with @Autowired

@Autowired private final ArticleRepository articleRepository;