3

I'm struggling with application.properties setup in maven multimodule project. I have structure

--parent
----core-api
----infrastructure (infrastructure.properties)
----command
----web (application.properties)

I'm using different names for appliaction.properties, because I want to load them all in target module.

I've read this and this posts so I decided to put

@PropertySource(value = { "classpath:application.properties","classpath:infrastructure.properties" })

to my Application.class in web module. But when I run command mvn spring-boot:run from my parent project I get exception:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.github.bilak.axonframework.poc.Application]; nested exception is java.io.FileNotFoundException: class path resource [infrastructure.properties] cannot be opened because it does not exist
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:180)

my project can be found here

  1. How can I have this working while using maven plugin? Is there way to setup this in java and run with maven?
  2. This is more related to maven, but can I run mvn spring-boot:run from web module without installing the dependent modules to local repository?

Thanks in advance

Community
  • 1
  • 1
bilak
  • 4,526
  • 3
  • 35
  • 75

1 Answers1

1

You could reuse Spring Boot infrastructure instead of doing your own thing. You could have applications-infrastructure.properties and enable the infrastructure profile.

Regarding your second question, no you should install the other modules first; you can also find a related discussion in #3436

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
  • That's true, that I can use properties as profile. But that doesn't work application-infrastructure.properties is not loaded I guess. I updated the project on github. – bilak Aug 12 '15 at 09:13
  • I ran your application and the infrastructure profile is loaded. So I don't know what your problem is. BTW you're not having a ServletInitializer in your web project so there's no chance you'll be able to deploy that war properly. Check https://spring.io/guides/gs/convert-jar-to-war/ – Stephane Nicoll Aug 12 '15 at 14:01
  • Problem is that h2 db should be created in folder ~/h2db/ and it's not there so I bet the application-infrastructure.properties is not loaded or it's loaded somehow incorrectly. – bilak Aug 12 '15 at 14:13
  • It's there for me (-rw-r--r-- 1 snicoll staff 208896 Aug 12 16:16 /Users/snicoll/h2db/axonpoc.mv.db). Anyway, there are better ways to figure out if the profile is loaded (the actuator for instance). – Stephane Nicoll Aug 12 '15 at 14:15
  • That's weird, it doesn't work for me - I don't see that db file, even if I try to change the server port in infrastructure.properties it doesn't change. Did you changed anything in my test project to work? – bilak Aug 12 '15 at 14:23
  • Ok so I've added actuator to the project and extended the ServletInitializer. When I look at /env endpoint and find infrastructure, I can't find application-infrastructure.properties there. I can find them only when i put them to web module. On which OS are you running my app? – bilak Aug 12 '15 at 14:46
  • MacOS but I'd be very surprised if it had anything to do with the problem. – Stephane Nicoll Aug 14 '15 at 06:16
  • OK I'm on the same OS. So can you somehow help me how to resolve this issue? If I look into the localhost:8080/env I see there only application.properties but not infrastructure-application.properties – bilak Aug 14 '15 at 06:22
  • I did 1. git clone url 2. mvn clean install 3. cd web 4. mvn spring-boot:run – Stephane Nicoll Aug 17 '15 at 08:30
  • Ok this way it works. I will mark this thread as correct, but shouldn't it work even if I run mvn clean spring-boot run from parent project? – bilak Aug 17 '15 at 10:02