In Spring MVC, class DefaultAnnotationHandlerMapping is deprecated. Documentation ( http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.html ) says:
Deprecated.
in Spring 3.2 in favor of RequestMappingHandlerMapping
Why is it deprecated? What practical problems of this class were fixed in RequestMappingHandlerMapping?
Spring Framework is an open-source project hosted on GitHub so all this information is easy to find in the code:
Find the source file in question: click
Switch to "blame" view: click
Find all occurences of "#Deprecated" to find the associated commit: click
Commit message mentions "SPR-10005", find it on Spring JIRA: click
The JIRA ticket contains a link to the "what's new in version 3.1.3" document: click
The relevant part:
The new classes were developed in response to many requests to make annotation controller support classes more customizable and open for extension. Whereas previously you could configure a custom annotated controller method argument resolver, with the new support classes you can customize the processing for any supported method argument or return value type.
Related
I am looking to provide the Facebook and Gmail login on Broadleaf application for which i am referring the below mentioned link
https://www.broadleafcommerce.com/blog/why-your-ecommerce-site-should-integrate-with-spring-social
however the link is quite older, can anyone please help me to send a link or pointers to do Spring Social login with Broadleaf version 5.2
Thanks in advance
I have not actually implemented this, but I think I can provide some pointers. The steps below are taken from the blog post. In general, the blog post is still correct, but declaring beans has moved from XML to Java since that post was written.
1) Add the Spring Social dependencies to your root POM
Follow the blog post.
You may want to update to the newest version of Spring Social (1.1.6 as of Jan 2020). Consult the Spring Social Documentation for updated dependencies. Specifically, you would need to add an additional dependency from what the blog post listed:
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>1.1.6.RELEASE</version>
</dependency>
The latest spring-social-facebook is 1.1.1 and the latest spring-social-twitter is 1.1.2.
2) Create a new applicationContext-social.xml
This is the step with the biggest changes. Broadleaf 5.2 supports declaring beans using Spring's #Configuration annotation on classes. This means that the beans defined in XML from the blog post can be defined in Java in a #Configuration class for Broadleaf 5.2.
The bean definitions for applicationContext-social.xml could be added to SiteConfig.java (or to a a new configuration class that gets component scanned from SiteConfig), and the bean definition for applicationContext-servlet.xml would go in SiteServletConfig.
Here is an example of the first bean listed in the blog post as Java configuration:
#Value("${facebook.clientId}")
private String facebookClientId;
#Value("${facebook.clientSecret}")
private String facebookClientSecret;
#Value("${twitter.consumerKey}")
private String twitterConsumerKey;
#Value("${twitter.consumerSecret}")
private String twitterConsumerSecret;
#Bean
public ConnectionFactoryRegistry connectionFactoryLocator() {
FacebookConnectionFactory facebookConnectionFactory = new FacebookConnectionFactory(facebookClientId, facebookClientSecret);
TwitterConnectionFactory twitterConnectionFactory = new TwitterConnectionFactory(twitterConsumerKey, twitterConsumerSecret);
ConnectionFactoryRegistry connectionFactoryRegistry = new ConnectionFactoryRegistry();
connectionFactoryRegistry.setConnectionFactories(Arrays.asList(facebookConnectionFactory, twitterConnectionFactory));
return connectionFactoryRegistry;
}
The entry for applicationContext-security.xml would go in SiteSecurityConfig, but it will need to be updated to comply with the new standards of Spring Security Java configuration. The configuration snippet from the blog post <sec:intercept-url pattern="/signin/**" requires-channel="https" /> simply requires that URLs under /signin are served over https. Serving the entire site over https has become standard since the blog post was written in 2012, so this step may not be necessary if your site is already doing that. Looking at our reference Heat Clinic application, its SiteSecurityConfig.java is already configured to serve all URLs over https.
If you do need to add an entry, in SiteSecurityConfig.java, find the method configure(HttpSecurity http) and add this to the configuration:
.requiresChannel()
.antMatchers("/signin/**")
.requiresSecure()
You can also add the String /signin/** to an existing requiresChannel antMatcher if it exists.
3) Modify your Broadleaf Runtime Properties
Same as blog post
4) Add your new applicationContext-social.xml to web.xml
This step is not necessary when using component scanning. I doubt you are using a web.xml file with Broadleaf 5.2.
5) Change your RegisterController to extend BroadleafSocialRegisterController
Same as blog post. You can see the framework controller at org.broadleafcommerce.core.web.controller.account.BroadleafSocialRegisterController
6) Finally, add the sign in buttons to your login page
Same as blog post. Adapt to your site's HTML.
I hope this helps. Feel free to ask any follow up questions.
I'm currently migrating existing components to use the HST-2 Spring Bean Bridge to integrate better with the Spring IOC container.
I followed the Hippo documentation and everything works as advertised, at least in the running site. I can now define my component beans in my spring configuration and use DI for my component dependencies.
However, I learned that now I cannot modify the parameters on those component's in the Channel Manager's Template Composer. Before migrating those catalog components to use the SpringBridgeHstComponent I could click in the component item area in the Template Composer and get the pop up dialog which let me view and edit all the parameters to that component item
(hst:parameternames, hst:parametervalues).
Now the pop up dialog just shows a message that
"No editable properties found for this component."
I should mention that the component parameter values that were already set on the components are still available during request processing/execution. But those values are now effectively "hard-coded" because the webmaster cannot view/change them in the Template Composer.
Is this a known issue with the SpringBridgeHstComponent? Or is there a workaround configuration or something to make those component parameters available again in the Channel's Template Composer?
The Hippo CMS Channel manager can only scan annotations in the component class configured by the hst:componentclassname property.
SpringBridgeHstComponent class itself, which is used in your component
configuration now, cannot be annotated by a domain-specific parameters
info annotation. As a result, it's not shown in the channel manager
properly.
If you want to enable the parameters setting window for the
SpringBridgeHstComponent-bridged component, then you should extend the
class only for the annotation. e.g, ContactSpringBridgeHstComponent
extends SpringBridgeHstComponent with a specific annotation in that
extending class for contact component for instance. See the docs for detail.
This is needed at the moment because channel manager recognizes the
parameters information only by class annotation, which makes you extend
a new class for each component.
I've decided to use custom template engine with Spring MVC framework.
my templates implemented in java and have method for rendering into String:
public String render(Map context);
how to configure spring to make them available in Controller beans as views, for example like:
ModelAndView modelAndView = new ModelAndView("activationPage"); // - view name which will actually be java class name reference.
modelAndView.addObject("validationResult", validationResult);
return modelAndView;
Model will be passed as context in code connecting spring and my template engine.
You need to implement org.springframework.web.servlet.View (which should be easy, you already have something very similar to the render method it needs), as well as org.springframework.web.servlet.ViewResolver, which maps the view names (e.g. "activationPage") on your custom views.
Once you have that, drop a bean of your ViewResolver class into the context, and (unless you've done something else that gets in the way) it should automatically be picked up by Spring and should just work. if you have other ViewResolvers already in there, they may get into a fight over who gets to resolve the view, in which case ask a new question.
Hi I am the author of Rythm template engine, about half year ago I am having the same requirement like you. What I did is to read the source code of Velocity and Freemarker view of SpringFramework. And then create the Rythm view for spring following their approach.
It's easy to follow something that is already there, and it makes your implementation in good quality to follow the official module. Good luck on you :-)
I provide a highly customisable application to my clients which is working totally by itself. But If one my client wants to overwrite any Controller, I want to replace my implementation by theirs. However just overwriting the controller causes an ambiguous definition of mappings.
I have been using Component Scanning to load beans.
The potential solutions came to my mind are:
Using component scanner with excluding by a custom filter? (This seems not so easy)
Using a xxxxPostProcessor to remove some beans? (How?)
Any help?
If I got your Question properly,
You can differ implementation by changing URL to particular Implementation name
Say Telecom is interface and AirtelImpl and RelianceImpl are Controllers then
Your request mapping
#RequestMapping(value= "/airtel/doBilling")
#RequestMapping(value= "/reliance/doBilling")
In this way, Implementation flow will differ.
I have followed these steps:
Created a custom annotation: #Devoted
Created a custom ImportBeanDefinitionRegistrar. Iterated already registered bean definitions to find out `#Devoted #Controller's and removed them.
Based on a request I will provide implementation details.
I am trying to put a "Contract" on a method call. My web application is in Spring 3.
Is writing customs Annotations the right way to go. If so, any pointers( I didn't find anything in spring reference docs).
Should I use tools like "Modern Jass", JML ...? Again any pointers will be useful.
Thanks
Using Spring EL and Spring security could get you most of the way. Spring security defines the #PreAuthorize annotation which is fired before method invocation and allows you to use Spring 3's new expression engine, such as:
#PreAuthorize("#customerId > 0")
public Customer getCustomer(int customerId) { .. }
or far more advanced rules like the following which ensures that the passed user does not have role ADMIN.
#PreAuthorize("#user.role != T(com.company.Role).ADMIN)")
public void saveUser(User user) { .. }
You can also provide default values for your contract with the #Value annotation
public Customer getCustomer(#Value("#{434}") int customerId) { .. }
You can even reference system properties in your value expressions.
Setting up Spring security for this purpose is not to hard as you can just create a UserDetailsService that grants some default role to all users. Alternatively you could make you own custom Spring aspect and then let this use the SpelExpressionParser to check method values.
if you don't mind writing some parts of your Java web application in Groovy (which is possible with Spring) I would suggest using GContracts.
GContracts is a Design by Contract (tm) library entirely written in Java - without any dependencies to other libraries - and has full support for class invariants, pre- and postconditions and inheritance of those assertions.
Contracts for Java which is based on Modern Jass is one way to write contracts.
http://code.google.com/p/cofoja/
As per the writing of this reply, this is pretty basic. Hopefully this will improve as we go on.
I didn't find an ideal solution to this, interestingly it is a planned feature for the Spring framework (2.0 implemented patch):
http://jira.springframework.org/browse/SPR-2698
The best thing I suggest to use JSR 303 which is for bean validation. AFAIK there are two implementations for this:
Agimatec Validations
Hibernate Validator
There's a guide here for integrating it into Spring, I haven't followed it through but it looks ok:
http://blog.jteam.nl/2009/08/04/bean-validation-integrating-jsr-303-with-spring/
I personally recommend C4J for 2 reasons:
It has Eclipse plugin so you don't need to manually configure it.
The documentation is written in a clear, structured format so you can easily use it.
Her's the link to C4J