SuccessHandler:
import React from 'react'
import ReactDOM from 'react-dom'
import {ButtonToolbar, Button} from 'react-bootstrap' // define individual controls to import
const buttonsInstance = (
<ButtonToolbar>
<Button bsStyle="primary" bsSize="large" active>Primary button</Button>
<Button bsSize="large" active>Button</Button>
</ButtonToolbar>
);
ReactDOM.render(buttonsInstance, document.getElementById('root'));
资源:
class SuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler{
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
final Authentication authentication) throws ServletException, IOException {
String targetUrl = determineTargetUrl(request, response)
redirectStrategy.sendRedirect(request, response, targetUrl)
}
@Override
protected String determineTargetUrl(HttpServletRequest request,
HttpServletResponse response) {
boolean hasAdmin =SpringSecurityUtils.ifAllGranted("ROLE_ADMIN");
boolean hasUser=SpringSecurityUtils.ifAllGranted("ROLE_USER");
if(hasAdmin){
return adminUrl;
}else if (hasUser){
return userUrl
}else{
return super.determineTargetUrl(request, response);
}
}
private String adminUrl
private String userUrl
public void setAdminUrl(String adminUrl){
this.adminUrl = adminUrl
}
public void setUserUrl(String userUrl){
this.userUrl = userUrl
}
}
我想知道虽然没有创建任何对象,但import successHandler.SuccessHandler
// Place your Spring DSL code here
beans = {
authenticationSuccessHandler(SuccessHandler) {
adminUrl = '/admin/adminPanel'
userUrl = '/'
}
}
和adminUrl
属性是如何被注入的?
据我所知,我们应该创建一个对象,例如userUrl
。这会使用Autowired创建对象,然后该对象将被注入资源bean中定义的属性。
但是,这里如何在没有创建任何对象的情况下注入属性?