我有一个MVC Java配置,但HandlerInterceptor不排除某些模式.
在标有xxx的行上,如果
1)我同时添加addPatterns("/**")和excludePathPatterns("*.ecxld")对HandlerInterceptor的InterceptorRegistration时,HandlerInterceptor.preHanlde()是不是在所有调用.例如.addPathPatterns("/**").excludePathPatterns("*.ecxld")
2)我只添加excludePathPatterns("*.ecxld")到HandlerInterceptor's InterceptorRegistration,HandlerInterceptor.preHanlde()仍然执行.
(其他拦截器被调用很好).
任何指针赞赏.
谢谢
@Configuration
public class MyMVCConfigurerAdapter extends WebMvcConfigurerAdapter {
 @Override
 public void addInterceptors(final InterceptorRegistry registry) {
     registry.addInterceptor(getInterceptorOne());
     registry.addInterceptor(getMyHandlerInterceptor())
                 .excludePathPatterns("*.ecxld");  // **xxx**
     registry.addInterceptor(getInterceptorTwo()
     );
 }
编辑:我的Spring框架版本3.0.5
这是一个小问题,当我点击语言转换器链接时,语言没有改变.
语言文件(messages_xx.properties)位于类路径i18n目录中.文件是:
i18n/messages_en.properties
i18n/messages_ar.properties
弹簧配置
<!-- Component scanner. This is used to automatically find Spring annotations like @Service and @Repository -->
    <context:component-scan base-package="com.keype" />
    <!-- Annotation driven programming model -->
    <mvc:annotation-driven />   
    <context:annotation-config />
    <mvc:resources mapping="/static/**" location="/static/" />
    <!-- Session Object Configuration -->
    <bean id="session" class="com.keype.system.Session" scope="session">
        <aop:scoped-proxy />
    </bean>
    <!-- The View Resolver -->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp"
          />
    <!-- i18n Configuration. Default language is english. Change language using ?language=en -->
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" …我知道为什么断言编程是好的,所以我想用JavaScript.但是,我不想向用户显示错误框,这是不寻常的事情.只是忽略它,让它们重试可能会更好.
例如,此代码将生成错误框并中断用户.
function getDomainFromURL(url) {
    assertTrue(url, 'URL should not be null');
    ...parsing
}
所以,我会这样做.
function getDomainFromURL(url) {
    if (!url) return;
    ...parsing
}
我想,第二个对可用性有好处,第一个对开发有好处.因此,IMO最好将这些结合起来并使其assert消失在生产代码上.
问题1 你是这么认为的吗?或者有什么不同的想法?
问题2 如果您这么认为,有没有什么好方法可以使用Spring3框架?
我一直试图设置一个非常简单的控制器/视图,但是无法使其工作.在我web.xml,我已经定义了一个<servlet>名为servlet-context.xml,运行正常.在servlet-context.xml,我设置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
<...other stuff in here... />
<mvc:annotation-driven />
除其他事项外.我的理解是这就是使用@注释所需要的一切.
在我的控制器中,我有:
@RequestMapping(value="/student/{username}/", method=RequestMethod.GET)
public String adminStudent(@PathVariable String username, @RequestParam String studentid) {
    return "student";
}
在我student.jsp看来,我有:
<p>This is the page where you would edit the stuff for ${username}.</p>
<p>The URL parameter <code>studentid</code> is set to ${studentid}.</p>
当我发出请求时http://localhost:8080/application/student/xyz123/?studentid=456,我得到了我期望的视图,但所有变量都是空白或为空:
<p>This is the page where you would edit the stuff for .</p>
<p>The URL …我使用spring 3.0,我有一个非常简单的问题,但在互联网上没有找到任何答案.我想生成一个路径(URI),就像在我的JSP中一样:
<spring:url value="/my/url" />
但在控制器内部.使用的相关服务是什么?谢谢!
编辑:可能与此有关:http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-resourceloader?对此没有更好的解决方案吗?
我对Quartz很新,我对工作生命周期有些怀疑.
假设我有一个单独的工作配置来做一些事情.
这项工作开始并结束其工作.当它再次触发它是同一个实例(可能设置为睡眠并由调度程序唤醒)或者它是一个新的作业实例(一旦作业结束它就被杀死,当再次满足触发条件时,创建一个新的作业实例) ?
我问这样的问题,因为当我调试我的应用程序(带有石英支持的Spring 3 mvc)时,我看到作业的新实例,并且每次触发作业时都会打开SimpleThreadPool $ WorkerThreadRun()的新线程,以便SimpleThreadPool $ WorkerThreadRun()线程堆积,永不终止.
我只是想知道这种行为是否正常还是我必须填补记忆;-)
谁能给我一些解释?提前致谢.
我需要使用RESTTemplate将自定义对象传递给我的REST服务.
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, Object> requestMap = new LinkedMultiValueMap<String, Object>();
...
requestMap.add("file1", new FileSystemResource(..);
requestMap.add("Content-Type","text/html");
requestMap.add("accept", "text/html");
requestMap.add("myobject",new CustomObject()); // This is not working
System.out.println("Before Posting Request........");
restTemplate.postForLocation(url, requestMap);//Posting the data.
System.out.println("Request has been executed........");
我无法将自定义对象添加到MultiValueMap.请求生成失败.
有人可以帮我找到一个方法吗?我可以简单地传递一个字符串对象而没有问题.用户定义的对象会产生问题.
感谢任何帮助!
我正在努力学习Spring安全性如何工作,所以我下载了一些示例项目,然后我尝试将该解决方案实现到我的项目中.但是当我尝试登录时,我收到404错误,并在我的地址栏中http://localhost:8080/fit/j_spring_security_check.我试着在这里查看类似的问题,但我无法意识到,如何将它应用到我的项目中.如果有经验丰富的人可以帮助我,我会非常感激.
我的app结构如下所示:

applicationContext.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:security="http://www.springframework.org/schema/security"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="cz.cvut.fit"/>
<import resource="classpath:applicationContext-security.xml"/>
</beans>
的applicationContext-web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:security="http://www.springframework.org/schema/security"
   xsi:schemaLocation="
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="cz.cvut.fit" />
<mvc:annotation-driven />
<security:global-method-security jsr250-annotations="enabled"
                                 proxy-target-class="true"/>
</beans>
的applicationContext-security.xml文件:
<beans xmlns:security="http://www.springframework.org/schema/security"
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
             http://www.springframework.org/schema/security
             http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<security:http pattern="/css/**" security="none"/>
<security:http pattern="/views/login.jsp*" security="none"/>
<security:http pattern="/views/denied.jsp" security="none"/>
<security:http auto-config="true" access-denied-page="/denied.jsp" servlet-api-provision="false">
    <security:intercept-url …我有一个弹出配置注销如下:
<logout logout-url="/abc/logout"
            logout-success-url="/abc/login"/>
现在我想以编程方式注销.我如何在Spring 3中实现这一点.我需要从我的一个具有以下def的控制器中注销.目前我正在做类似以下的事......这是个好主意..
 public void suppressUserProfile() {
   //...
   return "redirect:/abc/logout"; 
 }
我们有一个Quartz/Spring Batch作业,为了审计日志记录的目的,我们希望将它作为系统用户进行"认证".我们的一些方法依赖于获取SecurityContext来执行此操作.运行此作业的方式是可信的(或经过身份验证).我们不想实际使用密码或其他令牌(因为该过程基本上总是由石英生成).
我试过这个
private void authenticate() {
    UserDetails admin = userDetailsService.loadUserByUsername( "admin" );
    RunAsUserToken token = new RunAsUserToken(
            UUID.randomUUID().toString(), admin, admin.getAuthorities(), null , null );
    Authentication user = authenticationManager.authenticate( token );
    if ( user.isAuthenticated() ) {
        SecurityContext sc = new SecurityContextImpl();
        sc.setAuthentication( user );
        SecurityContextHolder.setContext( sc );
    }
}
但它导致了
org.springframework.security.authentication.ProviderNotFoundException: No AuthenticationProvider found for org.springframework.security.access.intercept.RunAsUserToken
而且我不确定一些RunAsUserToken参数是做什么的(例如密钥)或者我应该在Credentials方面提供什么.
我如何验证或以其他方式设置安全上下文,就像它被认证为此用户一样?
spring-3 ×10
spring ×5
spring-mvc ×5
java ×4
assert ×1
assertion ×1
javascript ×1
rest-client ×1
resttemplate ×1