Spring Boot has a config file named "application.properties" or "application.yml". My Spring Boot application is called "A".
My problem is that with these properties files when other applications depend on application A.
<dependency>
<groupId>org.baharan</groupId>
<artifactId>A</artifactId>
<version>1.0.1-releases</version>
<type>jar</type>
</dependency>
I have applications A, B and C.
B and C depend on A, so I had to move "application.properties" of A to B and C then B and C started successfully.
B and C share some property values, so I'd like to put
these common values into application.properties of A and only put project-specific values into B's and C's configuration.
Related
I created a new file known as "solverConfig.xml" under resources. I changed in application.properties, to write the following: quarkus.optaplanner.solver-config-xml=src/main/resources/solverConfig.xml. However, Quarkus does not recognize the classpath. It says: Invalid quarkus.optap lanner.solverConfigXML property (src/main/resources/solverConfig.xml): that classpath resource does not exist. I followed the response of Optaplanner and Quarkus solver config update. But, it does not work.
The solverConfig.xml is configured as:
<!-- Domain model configuration -->
<solutionClass>org.acme.optaplanner.domain.TimeTable</solutionClass>
<entityClass>org.acme.optaplanner.domain.Lesson</entityClass>
<!-- Score configuration -->
<scoreDirectorFactory>
<constraintProviderClass>org.acme.optaplanner.solver.TimeTableConstraintProvider</constraintProviderClass>
</scoreDirectorFactory>
<!-- Optimization algorithms configuration -->
<termination>
<minutesSpentLimit>1</minutesSpentLimit>
</termination>
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
</constructionHeuristic>
The src/main/resources prefix isn't part of the value for that property:
Either don't have a quarkus.optaplanner.solver-config-xml property in application.properties, which means it will pick up src/main/resources/solverConfig.xml (recommended, for standardization only)
Or set it explicitly to quarkus.optaplanner.solver-config-xml=solverConfig.xml to pick up src/main/resources/solverConfig.xml.
PS: solverConfig.xml in Quarkus doesn't need a entityClass, solutionClass or constraintProviderClass. It picks that up automatically.
I have properties file in Spring Boot application , with end points mentioned as below :-
user.details = /api/{userID}/get-user
I am using POJO with #PropertySource, #Configuration to read values.
Now my requirement is to replace the userID value dynamically from the java code after reading it from properties file, when I receive the ID from front end application. I will not pass this value from command line as it does not serve my use case.
I want to make my spring-boot configuration class A dependent on another configuration class B, i.e. A configuration is evaluated only if B configuration is evaluated.
In the real context, I have hundreds of Ai configurations and only one B, and I want to implement a way to exclude all the Ai configs by excluding only B during tests.
I tried the following:
#Configuration
#ConditionalOnBean(type = "org.my.B")
public class A1AutoConfiguration {
// ...
}
Where B is a unconditioned configuration class.
But when I run mvn spring-boot:run -Ddebug=true I see that A is never evaluated because B is missing. While the beans created inside B are in the application context, B itself is not.
I though I can make the Ai configuration classes dependent on beans created inside B but I don't like so much this solution.
Is there a cleaner (and working) way to implement such a dependency mechanism?
The key is to make sure that things are ordered correctly. It does not make any sense to request A to only apply if B is present if you can't make sure that B is evaluated first.
The hundreds part frightens me a bit. If As and B are auto-configuration, you can use the following
#AutoconfigureAfter(B.class)
#ConditionalOnBean(B.class)
public class A123AutoConfiguration { ...}
If As and B are not auto-configuration, you need to make sure B is processed first so you can't rely on regular classpath scanning for those.
I would say that such group of beans is suitable for separate library or sub-module, so that they are independent. Including mechanism can be component scanning on root package of such library or sub-module.
Other option is to use Spring profiles. Mark your beans with #Profile annotation and use #ActiveProfiles to enable certain group of beans during test.
I have three NodeEntities A, B, and C. A is the parent of B and C. C has a property of type Set. For all three entities I have also a PagingAndSortingRepository. The Spring Boot application is set up as in the example https://spring.io/guides/gs/accessing-neo4j-data-rest/.
Now there is a strange thing: If I browse the B-repository directly using the url localhost:8080/B I see all the parent properties that B inherits from A. But if I browse the Bs over C, like localhost:8080/C/0/B I see the Bs but all the inherited properties are empty. Is this a bug or is there something missing?
Do you have a sample project that reproduces this? Or at least share the code for the classes.
Could be that your B relationship needs to have a #Fetch annotation to be fully hydrated for the load.
Update
As I presumed, the transitive child is not loaded automatically, so if you really need the data there, then add the #Fetch annotation.
public class Composite extends Component {
#Fetch
private Set<Leaf> leaf;
....
}
I have several OSGi bundles (say A, B and C). Each of these bundles has its own Camel routes defined using Spring DM XML file.
I'd like to monitor each route by adding a wiretap at the beginning of each route. For example, the wiretaps would send data to a route defined in a different bundle (say Z)
...
<wiretap uri="direct-vm:data-gathering-route/>
...
In bundle Z, I would define the said route in a file named camelContext.xml. Its location is META-INF/spring, as follows:
<route>
<from uri="direct-vm:data-gathering-route"/>
...
</route>
The reason for defining this route in a separate bundle is because I don't want to repeat this in bundles A, B and C. So I hope I could import this route definition (within bundles A, B and C Camel Context files) using the Spring DM import statement, as follows:
<import resource="classpath:META-INF/spring/camelContext.xml"/>
When I deployed bundles A, B, C and Z in Karaf, it complains that it can't find the camelContext.xml file.
Am I approaching this the right way?
Thanks.