Primary and Secondary datasource using jakarta instead of javax - java

After upgrading to Java 17 and Spring Boot 3.0.1, jakarta is also replacing javax. You can add as many datasources as you like, as long as they share the same username/password and driveClassName. However, what if you have two datasources with different creds? There doesn't seem to be an equivalent to how javax handles this. i.e., see first answer here with the Config class...
Spring Boot configure and use two data sources
What is the jakarta equivalent or how do we configure this?

Related

Spring Boot 3 Actuator Indentation not working

Created a new Spring Initializer project in IntelliJ using Spring Boot version 3.0.2.
Included Spring Web and Spring Boot Actuator.
Did the same using Spring Boot version 2.7.8.
Both projects have the following in application.properties
management.endpoints.web.exposure.include=info
management.info.build.enabled=true
spring.jackson.serialization.indent-output=true
When requesting /actuator/info for version 3.0.2 project, the JSON is not indented or pretty printed.
The same request for version 2.7.8 project returns pretty printed and indented JSON.
Everything is left default, no code additions, config changes. etc. Just plain vanilla out of the box project.
Is this a bug in Spring Boot version 3?
Expected the JSON response to be pretty printed and indented as per the Spring documentation for the Application Properties settings.
This change has been introduced in Spring Boot 3 on purpose: changing a JSON configuration in your main application should not change the JSON format used by actuator, as it could confuse clients relying on the format to be the same for all Spring Boot applications.
See the related issuue and also the dedicated section in the migration guide. You can revert to the previous behavior by setting the management.endpoints.jackson.isolated-object-mapper=false configuration property.

How exactly spring.http.multipart.enabled is different from spring.servlet.multipart.enabled?

In Spring Boot, for multipart uploads, I see many of the tutorial sites suggests to have one of the below properties:
spring.http.multipart.enabled=false
or
spring.servlet.multipart.enabled=true
Can someone explain why these settings and their use cases? Especially if I set the property spring.http.multipart.enabled=false , then why spring.servlet.multipart.enabled=true
I tried searching through Stack Overflow, but did not find any relevant posts for this one.
spring.http.multipart.enabled has been replaced with spring.servlet.multipart.enabled
If you're using Spring Boot 2.0.0 or later you should use spring.servlet.multipart.enabled
See also:
additional-spring-configuration-metadata.json
Spring Boot Reference of 1.5.19.RELEASE version (the Common application properties section lists spring.http.multipart.enabled).
Spring Boot reference of 2.0.0.RELEASE version (replaced with spring.servlet.multipart.enabled)
Upgrading from an Earlier Version of Spring Boot
MultipartProperties (1.5.19.RELEASE)
MultipartProperties (2.0.0.RELEASE)

org.springframework.boot.SpringApplication with spring-core 3.2.5.RELEASE

I am going to create simple rest service using spring 3 and hibernate 3. There is no chance for me to use higher version of spring due to legacy business component that is based on hibernate 3.
For such purposes I've tried to use SpringApplication.run, bet recieved following exception:
Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames
Is it possible to use spring-boot-maven-plugin with old spring version? Would be good to know any alternative ways in this direction.
Spring Boot (and all the related tools, e.g the maven plugin) expect Spring v4 and above. Please see the official documentation here.
By default, Spring Boot 1.3.2.BUILD-SNAPSHOT requires Java 7 and Spring Framework 4.1.5 or above.

neo4j community V1.9 - how to specify path of config files in Spring?

I need multiple neo4j embedded databases running on the same machine, on different ports.
I'm building on Spring -- how best to configure via Spring to do that? Ideally I want separate property files for each app, rather than baking the ports in the code -- e.g. /etc/app1.conf, /etc/app2.conf, and to be able to specify the relevant ports and other properties in those files.
I understand that such configuration was once possible in earlier versions of neo4j through a EmbeddedServerConfigurator class, which is no longer present in 1.8+
I'm running 1.9.5 with an eye to 2.0 in the nearish future, so a non-deprecated way of doing this would be much appreciated.
D
Darrell, if you run embedded there are no ports and no config files.
You just provide store-directories and optionally database config to your GraphDatabaseService instances which are (in Spring Data Neo4j) created as spring beans.
Unfortunately there is no compatible way between 1.9 and 2.0 as the public constructors of EmbeddedGraphDatabase were removed in 2.0 and I added a GraphDatabaseServiceFactoryBean in SDN 3.0 / Neo4j 2.0.
To run a server with an embedded Neo4j you'd probably have to go the way of extending CommunityBootstrapper. But here is no out of the box way integrating this in Spring right now.
So to make it work, I'd probably create a subclass of CommunityBootstrapper which starts the server, but can be passed in the GraphDatabaseService from the outside.
See my in-memory-server project for some hints: https://github.com/jexp/neo4j-in-memory-server

Java Spring - Import resource based on Placeholder Expression

In Spring, I'd like to do the following:
<import resource="${resourceFile}" />
However, 'resourceFile' is not evaluated by the import.
The reason why I need it to work is I defined to two different resourceFiles:
resources-serviceA.xml
resources-serviceB.xml
Each of the above files define different sets of beans. When running ServiceA, I wouldn't need the beans needed just for ServiceB and hence I do not want to create them.
Any pointers on how to accomplish this?
We are using Spring 3.0.
Spring 3.0 can not evaluate properties inside import tag, evaluating those was one of the new features of Spring 3.1 (in 2011)
See Spring 3.1 M1: Unified Property Management
So basically you should use the actual version of Spring. Spring 3.1+ also introduced bean profiles, so you can define ServiceA and ServiceB in different profiles.
If you are interested how this problem was solved by users of Spring 3.0 you can look at Import Spring config file based on property in .properties file but keep in mind that Spring 3.0 is 3 years old now, it's suspicious to make changes in the basic bootstrapping configuration of the 3yo project, consider switching to Spring 4.0+.

Categories