SpringBoot 3: DataSource issue with SpringBatch 5 - spring-batch

As part of the migration to Spring Batch 5.0, the documentation says javax.* classes have been replaced with jakarta.*. However, Spring Batch API still references javax..
Here is an example with JdbcCursorItemReader.
#Configuration
public class Config {
#Autowired
private jakarta.activation.DataSource dataSource;
#Bean
public ItemReader<T> reader() {
JdbcCursorItemReader<T> reader = new JdbcCursorItemReader<>();
// Requires javax's datasource and not Jarkata.
reader.setDataSource(dataSource);
}
}
I don't currently see a path forward for me right now in reading to or from a database in Spring Batch 5 unless there is some documentation I can reference. I don't see it in the what's new or migration guide.

javax.sql.* is a JDK package and not part of Java EE. The latter lived indeed under the javax.* package and it has been taken over by the Eclipse foundation. Those APIs will evolve under jakarta.* packages. Javax as a name is trademarked and not donated to the community.
In short: you don’t todo anything here.
For reference, see the JDK Javadoc of DataSource
https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/javax/sql/DataSource.html
javax.activation.DataSource respectively jakarta.activation.DataSource are different APIs and neither are used by the JDBC item reader.

Related

Blazor dependency injection and EF/DbContext with private NuGet packages

I am trying to set up a Blazor project to be reusable through numerous other projects, and I am having issues understanding how Blazor's DI system works with NuGet packages.
In short, I built a simplistic Blazor app as a ticketing system for bug reports/requests. It collects simple information through input forms (built as components) and uploads tickets to a SQL Server database via Entity Framework and a connection string (stored in AppSettings.JSON). The DbContext is injected into the ticketing app's DI system via AddDbContextFactory. It all works perfectly within the solution.
My goal is: I want to package this ticketing system and reuse it throughout my other apps with minimal setup. In the other apps, I want to reuse the "AddTicket" components, which will simply accept some simple report data and update the ticketing databse.
As a test, I packaged the ticketing app as a NuGet package locally on my machine. I imported it into a separate host app. However, I had to recreate the connection string and the Dependency Injection (with the Context Factory and everything) in the host app to make the package work.
My problem is that I don't understand how Blazor's DI system works when I am building my own NuGet packages and I don't understand the flow of the dependency injections that are in Startup.cs versus what's in the NuGet package.
I just was a simple, reusable form and submittal component, with all of the EF and database logic built into it in the simplest way that I can drop into a dozen external projects.
What is the best way to build a NuGet package so that I don't need to do additional dependency injections in this situation? If I must do an additional entry into the host app's DI system, how do I make it as simple as possible?
When I create a library that has Injection. In my library I create a static class and create and extension method for IServiceCollection
public static class ServiceCollectionExtensions
{
public static void AddBlazorSyncServer(this IServiceCollection services)
{
services.AddScoped<ILogger, Logger<LoggingBroker>>();
services.AddScoped<ILoggingBroker, LoggingBroker>();
services.AddScoped<IDateTimeBroker, DateTimeBroker>();
services.AddTransient<ISyncDatabaseBroker, SyncDatabaseBroker>();
...
}
}
NOTE: In my example SyncDatabaseBroker is a DbContext :
public partial class SyncDatabaseBroker : DbContext, ISyncDatabaseBroker
This makes it a lot easier for the user to setup in their code base.
Databases have to be handled a little differently. When I want to manage migrations or share a connection strings I use this approach:
Program.cs (Library consuming server)
...
var migrationsAssembly = typeof(Program).Assembly.FullName;
builder.Services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer(
connectionString,
dbOpts => dbOpts.MigrationsAssembly(migrationsAssembly)));
builder.Services.AddDbContext<SyncDatabaseBroker>(
options => options.UseSqlServer(
connectionString,
dbOpts => dbOpts.MigrationsAssembly(migrationsAssembly)));
...
builder.Services.AddBlazorSyncServer();
Console commands I can then use for the migrations:
Add-Migration InitialApplicationSchema -Context ApplicationDbContext -OutputDir Data/Migrations/Application
Add-Migration InitialSyncSchema -Context SyncDatabaseBroker -OutputDir Data/Migrations/Sync
Update-Database -Context ApplicationDbContext
Update-Database -Context SyncDatabaseBroker

Vertx multiple event loops

I'm a beginner with Vertx and I'm using this link as the starter code.
However, there is no main file and I don't see how the MainVerticle is deployed. I would like to set some deployment options for the MainVerticle but since there is no main file; how would I do that?
I recommend this link for you to improve your vert.x knowledge from zero to hero.You will be able to make a crud application using this repository.
https://github.com/saranglohar/vertx-crud-operations-demo/tree/master/src/main/java/com/vertx/student/crud
The two common ways to do that :
build a fat jar using the maven shade plugin or exec plugin and the io.vertx.core.Launcher class as main class, according to this documentation. Then you will be able to run your fat jar with a java -jar command.
My favorite : use the vertx command line (like you would do with nodejs for example).
I'd prefer the second solution in order to avoid the duplication of the vert.x core library in your filesystem which can have a real cost when you have to run bunch of vert.x microservices.
Afterwards to go further you can encapsulate that with a resilient services orchestrator like systemd or even docker+kubernetes & co.
You can use main() very easily:
public class Application {
public static void main(String args[]) {
Vertx vertx = Vertx.vertx()
vertx.deployVerticle(new MainVerticle());
}
}

Eclipse Scout Neon : service registry does not contain a service of type

I try to call scout service from Scout Form, so I create interface in shared folder
#TunnelToServer
public interface IPersonsFormService extends IService {
void test();
}
and in server I created implementation of this interface
public class PersonsFormService implements IPersonsFormService {
#Override
public void test() {
System.out.println("TEST");
}
}
but I get
o.e.scout.rt.platform.exception.ExceptionHandler - SecurityException:service registry does not contain a service of type com.sixt.leasing.contract.scout.shared.person.IPersonsFormService [majorPrincipal: 'marko']
java.lang.SecurityException: service registry does not contain a service of type com.sixt.leasing.contract.scout.shared.person.IPersonsFormService
It looks like interface is not registered, but in Neon I thought that service is registered with #TunnelToServer annotation.
Where else should I register service ?
This project is extension project of main project.
In Main project all services works,....
Solution: put scout.xml with default content in src/main/resources/META-INF folder of the server project.
Why did this happen? Since this is an extension we apparently forgot to copy this file and Scout Neon seems to ignore projects that don't contain this file.
Figured this out by putting a PlatformListener in that project and since that never triggered it was easier to track down the issue.
This annotation is requested for Remote-Service (see also the 3.5.1. #TunnelToServer section). The implementation class (or the interface) should have the #ApplicationScoped annotation.
For Local-Service, use either the #Bean or the #ApplicationScoped annotation to register the service.
If your annotations are correct, your Jandex index might be broken.
Start the application with -Djandex.rebuild=true to rebuild the application on startup.
This will recalculate each of your target/classes/META-INF/jandex.idx files.
Of course, you can also delete each file manually. Running mvn clean also clean those files.

Set openejb javaagent in code?

I'm currently writing integration tests for a Java EE application and use openejb/openjpa.
But as I'm using CMP I have to use a javaagent to enhance my classes. In maven I can configure my surefire plugin to do this enhancement, or better set the agent as vm parameter to the test.
But as I'm currently developing I like to run my tests quite often in eclipse. But there I don't want to set the agent all the time via
java -javaagent:openejb-javaagent-4.6.0.jar _\[other params...](other-params....html)
Does someone have a useful solution for this problem?
For testing in Eclipse purposes, I always create a variable that can be used in the VM arguments section of your Run Configuration. This way all you need to specify is something like ${agent} (or whatever you call it) rather than the full javaagent string.
Mhh but not sure, looking at my properties, my classes should be enhanced at runtime:
#Before
public void startupContainer() throws NamingException {
Properties p = new Properties();
p.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
p.put("openjpa.jdbc.DBDictionary", "hsql(SupportsSelectForUpdate=true)");
p.put("openejb.embedded.initialcontext.close", "destroy");
p.put("openjpa.RuntimeUnenhancedClasses", "supported");
p.put("openjpa.DynamicEnhancementAgent", "true");
p.put("javax.persistence.lock.timeout", "0");
p.put("openejb.log.factory", "slf4j");
ejbContainer = EJBContainer.createEJBContainer(p);
}

JBoss ESB pipeline interceptors

I am new to JBoss ESB and I am trying to intercept and handle all messages that happen on my application server.
I found that pipeline interceptors are what I am looking for. However, I am unable to make them work. Could you direct me to any tutorial concerning this problematigue? I tried documentation for JBoss ESB but this section is very vague. Is there any working sample with pipeline interceptors? I have not found any...
Here is what I have tried:
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.message.PipelineInterceptor;
import org.jboss.soa.esb.message.Message;
public class Interceptor implements PipelineInterceptor {
#Override
public void processMessage(Message msg, ConfigTree arg1) {
System.out.println("Intercepted" + msg.getContext());
}
}
I programmed this very simple class and converted it into a .jar file and placed it in the root directory of my project. I also copied jbossesb-properties.xml next to it and uncommented the interceptors section. What else should I do? Where do I specify the path to my interceptor class?
Any help is appreciated...
Ok, after a day of trying everything possible, I think I have solved it. You have to place the .jar file with Interceptor somewhere in the path of ESB (the best way is probably to the folder with deployed ESB in AS) and specify path to it in jbossesb-properties.xml file...