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.
Related
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 ;-)
Attached my screenshot which is entry level rest class, where used #Component. Why used #Component ?
I gone through below blog
http://www.benchresources.net/jersey-2-x-web-service-integrating-with-spring-framework-using-annotation/
#Component, #Resource, #Service used because you are still using spring framework application for dependency injection, specifically to link to found classes by component scan, and you want it to be able to autowire spring components as you service or dao classes
I read Servlet is a Java EE specification and that involves packages javax.servlet , javax.servlet.http.
As a part of implementing the specification, one need to provide a class that defines Servlet interface (in package javax.servlet). So is this job done by Java EE itself through HttpServlet class (in package javax.servlet.http).
So I am confused is Java EE one that created Servlet specification and also provided implementation for that specification.
javax.servlet.http.HttpServlet is an abstract class , not an implementation. Java EE does provide any implementation for Servlet.
Servlet containers (like Tomcat, JBoss, GlassFish etc.) also contain the servlet-api.jar else they would not be able to run your web application, and moreover they also contain the implementation of the interfaces that are part of the Servlet API (here).
There is no default implementation for sure, implementation of servlet is a responsibility of application developer. As already mentioned, you need to extend javax.servlet.http.HttpServlet for this purpose.
And you do not need EE container to make it work, Web container is enough.
Is there a way to swap Pimple with Symfony dependency injection?
I can use Symfony dependency injection as a standalone package with Silex but i need to swap Pimple with it because i can't access controllers registered with Symfony dependency injection from Silex like:
$app->get('/route', 'testController:indexAction');
No you can't. Silex does not allow to change the container as the Silex main class extends from Pimple itself. If you need the Symfony container you should go with Symfony and not with Silex.
You could hack up a solution in which every call to Pimple is forwarded to DIC (Pimple would be a kind of proxy service only), but I wouldn't go that route.
Keep in mind that with the upcoming Symfony 4 (due on November, but there is a preview already aviable) the framework is going to be more like Silex: instead of having it all and remove the parts you don't use, you'll start small and add components/bundles/libraries into your project (check out Symfony flex).
Finally, as a side note/fun fact, there was a project from igorw (one of the coauthors of Silex) which replaced Pimple with Symfony DIC component, but it was more an academic exercise rather than a ready to use framework (it did work)
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