kazmura11 / multi-module-project-sample

Spring Boot Maven Multi Module Project with MongoDB and PostgreSQL
0 stars 1 forks source link

Seems like my ide can't find some resources #1

Open Ariloum opened 4 years ago

Ariloum commented 4 years ago

I've tried to open it in idea for java 8 and 11, got same behave:

  1. can't autowire PackageConfig
  2. can't find yaml link @EnableJpaRepositories(basePackages = {"${packages.common.postgres.repository}"},

2020-05-09 09_13_45-multi-module-project-sample  C__workspace_multi-module-project-sample  -  _mul

Is there anything I'm trying to do wrong way?

kazmura11 commented 4 years ago

@Ariloum Thank you for your feedback! I am new to IntelliJ. I'd like to tell you that I always use Eclipse. There is no problem to run this Spring boot app.

This seems to be a problem only in IntelliJ. Maybe, this is caused by Lombok.

If you have never used Lombok, install this: https://projectlombok.org/. If you use IntelliJ, you should install this plugin here: https://plugins.jetbrains.com/plugin/6317-lombok, and restart the IDE.

Ariloum commented 4 years ago

I've tried to update 2018 idea to 2020, issue still persists. I've lombok plugin already installed, the case is something else.

Seems like EnableJpaRepositories can't see dependency in yaml config - if I change ${packages.common.postgres.repository} with it's yaml class link basePackages = {"com.example.multiModule.common.spring.postgres.repositories"} - this annotation works.

But still can't @autowire PackageConfig packageConfig;

kazmura11 commented 4 years ago

@Ariloum Sorry. I missed your message. I will take a look at it this week, so please wait a moment. I wonder why. Using @ConfigurationProperties in multimodule-common/src/main/java/.../configs/PackageConfig.java and src/main/resources/application-common.yml, I passed variable to basePackages in PostgreConfig.java. So just like you said, ${packages.common.postgres.repository} is equivalent to com.example.multiModule.common.spring.postgres.repositories. And check why the field is not autowired.

kazmura11 commented 4 years ago

image

I checked it in IntelliJ IDEA 2020.1.1 (Community Edition). But there were no errors. Show me the result running mvn install in this project. I will continue to investigate it.

Ariloum commented 4 years ago

it builds fine with maven, there is only highlight in the idea 2020-08-07 18_08_56-cmd

kazmura11 commented 4 years ago

@Ariloum Similar issues have been reported for IntelliJ idea. https://youtrack.jetbrains.com/issues/IDEA?q=build%20maven This link may solve your problem.

Try to delete all .iml and your POM. Then copy and paste your POM again to your project and re-open and re-import it.
Or, `mvn idea:idea` solves the issue.

https://stackoverflow.com/questions/18316857/maven-package-works-but-intellijs-build-fails

Ariloum commented 4 years ago

I tried to delete all idea files and mvn idea:idea and then reimport the project - nothing changed. I think it might be related to something with yaml or absent application-context.xml

kazmura11 commented 4 years ago

@Ariloum I tried to reproduce the problem, but cannot reproduce it.

Launch command prompt. Run command below:

> mkdir test
> cd test
> git clone https://github.com/kazmura11/multi-module-project-sample.git
> cd multi-module-project-sample
> pushd docker
> docker-compose up -d
> popd
> cd multi-module-batch/sample-db-access
> mvn spring-boot:run
(or > mvn install && java -jar target/sample-db-access-0.0.1.jar)

This works fine.

I don't think this problem is not related to yaml or other configs. If that assumption is correct, it shouldn't work. I used "Profile Specific Properties" with spring.profile.include and @ConfigurationProperties.

multi-module-batch/sample-db-access/src/main/resources/application.yml

app:
  packages: com.example.multiModule.sampleDbAccess
spring:
  datasource:
    postgres:
      url: jdbc:postgresql://localhost:5433/postgres
      username: postgres
      password: postgres
    mongo:
      host: localhost
      port: 27018
      database: mongo
  profiles:
    include: common  # <- search application-"common".yml in the class-path, insert its properties. 

multi-module-common/src/main/resoruces/application-common.yml

packages:
  common:
    component: com.example.multiModule
    postgres:
      entity: com.example.multiModule.common.spring.postgres.entities
      repository: com.example.multiModule.common.spring.postgres.repositories
    mongo:
      entity: com.example.multiModule.common.spring.mongo.entities
      repository: com.example.multiModule.common.spring.mongo.repositories

https://www.logicbig.com/tutorials/spring-framework/spring-boot/profile-specific-properties-with-include-property.html
https://docs.spring.io/spring-boot/docs/1.2.0.M1/reference/html/boot-features-profiles.html#boot-features-adding-active-profiles
https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/html/boot-features-profiles.html#boot-features-adding-active-profiles


I tried another experiment. I created a new virtual windows machine on Hyper-V (Windows 10 Enterprise Evaluation), there is no Java Environment .

  1. Install IntteliJ IDEA
  2. Featured plugins: Maven
  3. Get From Version Controll: install git
  4. Clone from git and import project
  5. Install lombok plugin Lombok Requires Annotation Processing: Do you want to enable annotation processors? -> Enable Still erros are shown.
  6. Rebuild Project and set SDK Project SDK: No SDK -> AdoptOpenJDK(HotSpot) 1.8.0_265 Errors are disappeared.
  7. Install docker(Docker Desktop) & Run docker containers

    cd docker && docker-compose up -d

  8. Run Spring Boot app. Right click on SampleDbAccessApp, then click run
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.6.RELEASE)

2020-08-19 06:40:26.615  INFO 7192 --- [           main] c.e.m.sampleDbAccess.SampleDbAccessApp   : Starting SampleDbAccessApp on WinDev2007Eval with PID 7192 (C:\Users\User\IdeaProjects\multi-module-project-sample\multi-module-batch\sample-db-access\target\classes started by User in C:\Users\User\IdeaProjects\multi-module-project-sample)
2020-08-19 06:40:26.615  INFO 7192 --- [           main] c.e.m.sampleDbAccess.SampleDbAccessApp   : The following profiles are active: common
2020-08-19 06:40:27.082  INFO 7192 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-08-19 06:40:27.082  INFO 7192 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-08-19 06:40:27.145  INFO 7192 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 47ms. Found 1 repository interfaces.
2020-08-19 06:40:27.160  INFO 7192 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-08-19 06:40:27.160  INFO 7192 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-08-19 06:40:27.176  INFO 7192 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16ms. Found 1 repository interfaces.
2020-08-19 06:40:27.798  INFO 7192 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-08-19 06:40:28.236  INFO 7192 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-08-19 06:40:28.298  INFO 7192 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: postgres
    ...]
2020-08-19 06:40:28.400  INFO 7192 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.10.Final}
2020-08-19 06:40:28.401  INFO 7192 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2020-08-19 06:40:28.666  INFO 7192 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2020-08-19 06:40:29.003  INFO 7192 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL95Dialect
2020-08-19 06:40:29.916  INFO 7192 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000421: Disabling contextual LOB creation as hibernate.jdbc.lob.non_contextual_creation is true
2020-08-19 06:40:29.924  INFO 7192 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@75fa1be3
2020-08-19 06:40:30.526  INFO 7192 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'postgres'
2020-08-19 06:40:31.230  INFO 7192 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27018], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2020-08-19 06:40:31.489  INFO 7192 --- [localhost:27018] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:1}] to localhost:27018
2020-08-19 06:40:31.497  INFO 7192 --- [localhost:27018] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27018, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 13]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=6171300}
2020-08-19 06:40:31.783  INFO 7192 --- [           main] c.e.m.sampleDbAccess.SampleDbAccessApp   : Started SampleDbAccessApp in 6.117 seconds (JVM running for 7.084)
Hibernate: 
    insert 
    into
        postgres_sample
        (name) 
    values
        (?)
2020-08-19 06:40:31.966  INFO 7192 --- [           main] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
Hibernate: 
    select
        postgressa0_.id as id1_0_,
        postgressa0_.name as name2_0_ 
    from
        postgres_sample postgressa0_
PostgresSample(id=1, name=John)
2020-08-19 06:40:32.695  INFO 7192 --- [           main] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:2, serverValue:2}] to localhost:27018
MongoSample(id=5f3d2bd0a7f95d1c18a6b9f0, name=Kate)
2020-08-19 06:40:32.923  INFO 7192 --- [       Thread-3] org.mongodb.driver.connection            : Closed connection [connectionId{localValue:2, serverValue:2}] to localhost:27018 because the pool has been closed.
2020-08-19 06:40:32.934  INFO 7192 --- [       Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'postgres'
2020-08-19 06:40:32.935  INFO 7192 --- [       Thread-3] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-08-19 06:40:32.938  INFO 7192 --- [       Thread-3] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

Process finished with exit code 0

image