Using spring-kafka as configuration framework - spring-kafka

My question may sound weird, but still.
Is it possible to use spring-kafka only as a configuration framework - like parsing application.properties or application.yaml and instantiate consumer and producer without Spring Boot Autoconfiguration facilities? Basically, minimal sprinkles of spring and spring-kafka for just public static void main application.
Thank you

Not sure what you mean with a "configuration framework", but from your description it sounds like you still want to use spring-kafka. So, there is nothing wrong to have a PropertySourcesPlaceholderConfigurer to resolve #Value annotations for configuration properties against your application.properties in the #PropertySource.
See docs for more info: https://docs.spring.io/spring/docs/5.2.4.RELEASE/spring-framework-reference/core.html#beans
See sample in Spring for Apache Kafka docs how to configure spring-kafka without Spring Boot: https://docs.spring.io/spring-kafka/docs/2.4.3.RELEASE/reference/html/#with-java-configuration
So, you need to combine spring-kafka feature with that #PropertySource + #Value for parsing configuration properties.
Essentially you are going to do whatever Spring Boot does for you ;-)

Related

Upgrading from Spring 2.5.x to Spring 4.x

I need to upgrade a medium sized web application from Spring 2.5 to Spring 4.x.
I replaced Spring 2.5 jars with 4.3.2 jars and I found around 100 errors like SimpleFormController name not resolved, queryforInt() not recognized etc. Should I use #Controller for controllers and use auto-wire the dependencies ?. That means I should convert all classes to annotation based using #component, #Resource, #Controller etc ? What is the best approach...Please suggest
You need to move from using SimpleFormController, it has been deprecated from spring 3.x and removed in 4.x. Start writing your controllers with #Controller annotation.
Should you use #Component, #Service, and autowire? It's probably best you do that, but not necessarily. You can still use your factory classes to create objects if you want. But using spring #Autowired dependency would make your life easier.

Deltaspike ConfigProperty working for EJB but not for simple bean in Wildfly 8.1

I am using Apache Deltaspike 1.0 to inject properties into the beans within my application. I am curious whether the observation I made indicates a bug or not. I created a simple managed bean that was annotated with #ApplicationScoped and everything worked fine. Then I activated Wildfly's sub-deployment isolation mechanism (see the relevant section in the docs). Afterwards, the properties are no longer injected.
However, if I "promote" my managed bean to an EJB with #Singleton #Startup the properties are injected again. I actually don't need most of my beans to be EJBs but I did not find any other way at the moment.
Any thoughts?
Thanks in advance
Sven
The problem is not directly related to Wildfly 8.1, but to the combination with camel-cdi. I explained it in the Wildfly forums: https://community.jboss.org/thread/242945

spring based bundle in apache felix osgi

I am working one POC where I want to create plugin based web application. Main application will have all the spring mvc context. Plugins can write spring controllers but they cannot have their own spring context file. What I want is when plugin is installed all its controller is scanned (plugins controller need to be in specific package so for that package component scan will be defined in parent context) and ready to use. I am able achieve the installation part however when I am trying to access bundle/plugin controller end point through rest call I get no mapping found error.
Has anyone tried something like this? It will be great if I can get reference to some example.
Thanks!!!
If you remove the spring part, I've already done this with
a) Apache Wicket and Pax Wicket
b) Vaadin
For a) you might want to look at the Apache Karaf WebConsole.
For b) take a look at this rather "old" showcase of mine.
Both of those showcases use either standard OSGi services or Blueprint for the services (http-services) and the discovery of new "web-components" or views.

A welcome message, that is pulled from a servlet that is configurable from the OSGi console

I am new to CQ5. I created a bundle that is configurable via the OSGi console. Now, I need the value that is configured on the console to be returned to my content page. I am not sure how to proceed with this. Looking for any tutorial or help. Thanks in advance.
Assuming the configured value is available via an OSGi service, you can access that service from java code using an #Reference SCR annotation with a suitable build setup to generate the corresponding OSGi metadata. You can also access OSGi services from scripts, in JSP that's done using sling.getService(YourService.class) in a script where you have called or its CQ equivalent.

Securing JAX-RS in a bundle

I am creating a REST service in glassfish (which uses Jersey as the JAX-RS impl.). I want to deploy my service as an OSGI bundle which works fine, I add the "Web-ContextPath:" in the manifest and then use an annotated #javax.ws.rs.ApplicationPath application object. This all makes the service usable but then, I want to use container based security. I found I can use security contrains in a web.xml and then do the user-to-role mappings in sun-web.xml. That said, a OSGI bundle does not have either.
Is there a set of annotations and or parameters to the manifest where I can specify application roles, security constrains and role-user mappings (I think the latter can just be globally configured)?
Thanks!
Here's how I would try this:
Use a library that would automatically detect OSGi services with specific annotations, and translate them to REST resources. For Jersey, you could try this: https://github.com/hstaudacher/osgi-jax-rs-connector
Use OSGi embedded application server like jetty (or tomcat) which provides the OSGi HTTP Service implementation.
Configure Jetty/Tomcat. This should be easy now as the Jetty/Tomcat bundles can pick up configurations from the configuration area.
It would also save a lot of time to use Karaf which would do all the packaging related work for you, including providing features like embedded Jetty with externalized configurations, etc. But that's totally up to you.

Resources