Tag: spring

Spring MVC:如何为索引页面创build一个默认的控制器?

我正在试图做一个标准的弹簧mvc hello世界应用程序,但我想把控制器映射到根。 (例如: http : //numberformat.wordpress.com/2009/09/02/hello-world-spring-mvc-with-annotations/ )所以唯一真正的区别是他们将其映射到主机\ appname \和我想将其映射到主机\ appname。 我将我的index.jsp放在src \ main \ webapp \ jsp中,并将其作为welcome文件映射到web.xml中。 我试过了: @Controller("loginController") public class LoginController{ @RequestMapping("/") public String homepage2(ModelMap model, HttpServletRequest request, HttpServletResponse response){ System.out.println("blablabla2"); model.addAttribute("sigh", "lesigh"); return "index"; } 作为我的控制器,但我没有看到我的tomcat的控制台中没有出现。 有谁知道我在搞什么? 我的web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!– Index –> <welcome-file-list> <welcome-file>/jsp/index.jsp</welcome-file> </welcome-file-list> […]

另一个未命名的CacheManager已经存在于同一个VM(ehCache 2.5)

这是当我运行我的junittesting时发生的事情… Another CacheManager with same name 'cacheManager' already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following: 1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary 2. Shutdown the earlier cacheManager before […]

Spring:关于path的/ **和/ *的区别

当我们引用path时,两个星号之间的区别是什么,而不是一个星号? 早些时候我正在debugging我的Spring 3项目。 我试图添加一个.swf使用 <spring:url var="flashy" value="/resourceshttp://img.dovov.comflash.swf"/> 用我的web.xml的ResourceServlet看起来像 <servlet-name>Resource Servlet </servlet-name> <url-pattern>/resources/*</url-pattern> 但不幸的是我得到这个错误: WARN org.springframework.js.resources.ResourceServlet – An attempt to access a protected resource at http://img.dovov.comflash.swf was disallowed. 我发现它真的很奇怪,因为我的images文件夹中的所有图片都被访问过,但是我的.swf怎么被“保护”? 之后,我决定将/resources/*更改为/resources/** ,最后运行。 我的问题是…为什么?

Spring / Java错误:JDK 1.5及更高版本中的命名空间元素“annotation-config”…

我有与编译器合规性级别1.5编译的Spring / Java应用程序。 我有一个新的Linux设置,我下载了Apache Tomcat 8.0.8 。 我下载了JDK 8u5 。 我在bash中设置path如下: PATH=$PATH:$HOME/jdk1.8.0_05/bin export PATH Java -version报告: java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) 并设置在setnenv.sh(对于Tomcat): JDK_HOME=/home/userid/jdk1.8.0_05 当我部署我的WAR文件时,我得到以下错误。 我觉得Tomcat似乎没有使用我安装的Java。 我已经按照设置说明。 PS:我也尝试过JRE,而不是JDK,也是同样的问题。 22-May-2014 11:34:54.070 INFO [http-nio-8080-exec-4] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext 22-May-2014 11:34:54.512 SEVERE [http-nio-8080-exec-4] org.apache.catalina.core.StandardContext.listenerStart Exception […]

Spring mvc控制器REST服务需要访问头信息。 如何在springmvc做到这一点?

我是一般的networking编程新手,特别是在java中,所以刚刚学到了什么是头和身体。 我正在使用MVC编写RESTful服务。 我能够在我的控制器中使用@RequestMapping创build简单的服务。 我需要帮助,了解如何从REST服务控制器中的方法获取标题信息。 我想parsing出头,并从中获得一些属性。 你能解释我怎么得到这些信息?

如何使用@ComponentScan注释扫描多个path?

我正在使用Spring 3.1并使用@Configuration和@ComponentScan属性来引导应用程序。 实际的开始是完成的 new AnnotationConfigApplicationContext(MyRootConfigurationClass.class); 此configuration类使用注释 @Configuration @ComponentScan("com.my.package") public class MyRootConfigurationClass 这工作正常。 不过,我想更具体的扫描包,所以我试过。 @Configuration @ComponentScan("com.my.package.first,com.my.package.second") public class MyRootConfigurationClass 然而,这个失败告诉我,它无法find使用@Component注释指定的组件。 什么是正确的方式来做我所追求的? 谢谢

注释configurationreplace为mvc:资源 – Spring

我试图升级我的springmvc项目,以利用新的注释,摆脱我的XML。 以前,我正在用我的web.xml加载我的静态资源: <mvc:resources mapping="/resources/**" location="/resources/" /> 现在,我正在利用WebApplicationInitializer类和@EnableWebMvc注释来启动我的服务,没有任何XML文件,但似乎无法弄清楚如何加载我的资源。 有没有一个注释或新的configuration拉回这些资源而不必使用XML?

com.sun.jdi.InvocationException发生调用方法

我只是想创build一个类的对象,但debugging时得到这个错误。 有谁可以告诉我问题是什么? 这段代码的位置在一些Spring(2.5)服务类中。 还有一个类似的问题: OJB参考描述符1:0的关系? 我应该设置自动检索为false? 非常感谢〜

如何手动注销弹簧安全的用户?

可能答案很简单:如何在春季安全中手动注销当前login的用户? 打电话是否足够? SecurityContextHolder.getContext().getAuthentication().setAuthenticated(false); ?

找不到具有URI的HTTP请求的映射…在名称为的DispatcherServlet中

我已经检查了几乎所有相关的文章,但我只是不能解决我的问题。 这是代码:web.xml: <display-name>Spring3MVC</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>spring</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.html</url-pattern> <url-pattern>/</url-pattern> <url-pattern>*.htm</url-pattern> </servlet-mapping> </web-app> 为spring-servlet.xml: <context:component-scan base-package="com.mycompany.elso" /> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> myController的: public class myController […]