Unable to extend BaseCommandController in Eclipse - spring

I am new to Spring and I am trying to extend BaseCommandController but Eclipse doesn't show it. I can extend AbstractController but not BaseCommandController. I have added all jar files from spring-framework 4.2.2.RELEASE.
What should I do to solve this problem?

You are not able to extend BaseCommandController because it is deprecated since Spring 3 and got removed in Spring 4.
The Spring way is now to use annotations as mentioned in the deprecation comment:
#deprecated as of Spring 3.0, in favor of annotated controllers
You should have a look at the Getting Started guide of Spring MVC where you can find a good example of the #Controller annotation

Related

Spring vs JAX-RS

Here, several questions have been asked by many developers about difference between Spring-Rest and JAX-RS.
And, I have also learned that Spring is not following any specification and Spring framework has their own implementation then
Why Spring allows all that Annotations which are supported/used by JAX-RS by default?
Spring does not support JAX-RS annotations. If there is a situation where you think they do, then you are mistaken or it's just a coincidence. Period. If you will add any JAX-RS annotations in my Spring MVC program, nothing will happen. Annotations are just metadata. They are not programs. If Spring does not recognize the metadata, it will ignore it. But if you use a JAX-RS annotation in place of a Spring annotation that is used for the same purpose, respective of their framework, then you will not get the expected Spring behavior. So basically, if you are using Spring MVC, remove any JAX-RS dependencies so you don't mistakenly use them.

Spring Boot 2.0.2 - Missing classes MetricRepositoryAutoConfiguration, MetricFilterAutoConfiguration

in Spring Boot 1.5 application the application class was annotated with:
#EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
These classes were I believe in the package:
import org.springframework.boot.actuate.autoconfigure.*;
Now upgrade to Spring Boot 2.0.2 but those classes are missing, can't find them anywhere.
What changed? How to solve?
Thanks!
Spring Boot’s own metrics have been replaced with support, including
auto-configuration, for Micrometer and dimensional metrics.
if you want to disable metrics set management.endpoint.metrics.enabled=false
there is a complete guide that makes migration a lot easier
Spring Boot 2.0 Migration Guide

Minimum version of spring for spring-boot v 1.3

I have an existing spring application built using spring framework version 3.1.2. I am trying to create a spring-boot application out of this existing application, but getting some dependency issues. So just wondering, what is the spring framework version, that is supported by spring-boot v 1.3.0.
Or to put it in another words, is it possible to have a spring-boot application from a spring 3.1.2 based application?
Spring boot has hard dependencies on classes in Spring 4 and could not be configured to work with Spring 3. If you are really interested in using Spring Boot the only way you can do this is to follow a migration path to Spring 4 and then add Spring Boot to your application.
It is worth mentioning that the "boot" in Spring Boot is meant to be short for bootstrapping, as in initial setup of an application. I'm not saying there would be zero benefits from migrating from Spring 4 vanilla to Spring Boot. But make sure you are migrating for the right reasons the main purpose of Spring Boot is easy bootstrapping of applications but here are some other features which might be worth making the move.
Spring Boot dev-tools (Auto restart on code changes)
Awesome spring boot plugins for maven and gradle to ease upgrading spring in the future (hint it upgrades many other dependencies for you)
Bootstrapping new features such as MongoDb through auto-configuration.
Migration from 3.1 to 3.2
https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/migration-3.2.html
Migration from Spring 3 to Spring 4.
https://spring.io/blog/2014/01/30/migrating-from-spring-framework-3-2-to-4-0-1
There are many features in spring boot that are dependent upon new features added to Spring 4. One primary example is the new list of annotations added to Spring 4 that allow conditional wiring/loading of beans. Which is the primary method of wiring configurations in a plugin-like way.
For example lets see the AutoConfiguration class for the H2 console
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java
The first thing we see is it's wired to be a Configuration class. It will only load if WebServlet.class is on the classpath and if the property spring.h2.console is = true. It is also configured to load SecurityAutoConfiguration first as this is a dependency at least for securing the h2 console page.
#Configuration
#ConditionalOnWebApplication
#ConditionalOnClass(WebServlet.class)
#ConditionalOnProperty(prefix = "spring.h2.console", name = "enabled", havingValue = "true", matchIfMissing = false)
#EnableConfigurationProperties(H2ConsoleProperties.class)
#AutoConfigureAfter(SecurityAutoConfiguration.class)
public class H2ConsoleAutoConfiguration {
When this Configuration is loaded it will check these conditions and upon all conditions being true then and only then will it load in the beans defined in the class. In this case it wires the h2console servlet.
#Bean
public ServletRegistrationBean h2Console() {
String path = this.properties.getPath();
String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
return new ServletRegistrationBean(new WebServlet(), urlMapping);
}
There is also the security configuration in that class which introduces one more concept of conditionally loading a configuration based on another class being loaded into the context. These annotations do not always need to be on a Configuration level but can also apply to the bean level.
These concepts are core to how Spring Boot is implemented and therefore could not work with Spring 3.
Spring 3 list of annotations
http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/context/annotation/
Spring 4 Conditional Annotations
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/
Thanks Zergleb for posting detailed answer. I found a way to run the spring 3 app as an independent jar by created an uber jar with a little instrumentation to bootstrap spring through a java class.
It is explained nicely in a short post at https://mihhaillapushkin.wordpress.com/2013/02/18/spring-3-for-standalone-applications

Spring 4 using Groovy setup

Spring 4.0 has improved support for Groovy e.g. using the GroovyBeanDefinitionReader.
What would be setup to to have a full Spring MVC application using Groovy?
E.g. using GroovyBeanDefinitionReader and AnnotationConfigWebApplicationContext together.
Anyone knows if there is a sample available or some pointers on a blog site?
You might want to check out spring boot, still in milestone release behind Spring 4 but they were really pushing its groovy support at spring eXchange.
Check out the bottom of this spring-boot guide
It's not quite the use of GroovyBeanDefinitionReader and AnnotationConfigWebApplicationContext you asked for, but I can't see why you couldn't do what you are after with the opinionated approach used by spring boot and the standard configuration annotations on groovy classes.
The git hub repository shows a number of annotated groovy examples
with ui.groovy for example, showing a configuration class for the WebMvcConfigurerAdapter defining a bean.
In your main method, do SpringApplication.run(new Object[]{JavaConfig.class, "beans.groovy"}, args), where JavaConfig contains your configurations in java (like #Configuration, #ComponentScan and etc., I generally find these things are easier using annotations) and beans.groovy just contain your spring beans DSL.
Assuming beans.groovy is on classpth (i.e. under src/main/resources)

JBoss 5.1: Spring #Resource annotation not working

I am working on an application using Spring 3 and Hibernate 3.5 with Java 1.6.
So far I've been using JBoss 4.2.1 and everything was fine.
Now while migrating to JBoss 5.1, I encountered lot of issues. One of them is that JBoss is ignoring the Spring #Resource annotation. I get the following exception:
java.lang.RuntimeException: mapped-name is required for serviceManager of deployment pol-1.0.war
at org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXmlResourceEnvRefs(WebResourceHandler.java:287)
at org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXml(WebResourceHandler.java:325)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.processMetadata(TomcatInjectionContainer.java:550)
at org.jboss.web.tomcat.service.WebCtxLoader.start(WebCtxLoader.java:158)
It expects mapped-name for each #Resource like some ejb.
I've seen similar questions but they are without any answer e.g.:
#Resource annotation not working properly with JBoss5.0.1
Please advise.
Adi
Actually your problem is that JBoss doesn't ignore #Resource annotations - it tries to handle them according to EJB rules instead of leaving them to Spring.
Perhaps this feature can be disabled somewhere in JBoss configuration, but the simpliest solution would be to replace #Resource with #Autowired or #Inject.
Sounds like java annotations need namespace support.
Then it would be #Spring:Resource or #EJB:Resource.
Oracle, are you listening?
Short of namespace for Annotations, you could possibly try changing the order of the libraries in your classpath so java would see the Spring annotations first (or last), whichever ends up providing the desired outcome.

Resources