博文

目前显示的是标签为“spring”的博文

Spring - Flash scope and Post-Redirect-Get pattern

What is flash scope? Flash scope is a concept which does not exist in Spring, but in JSF 2 and Play framework.  It is a scope between request scope, which is created and removed for each request, and session scope, which last for entire user session.  Flash scope is used in the Post-Redirect-Get pattern. Attributes kept in flash scope, using flash bean , will be available during the current request and the next request. What is  Post-Redirect-Get ? How to achieve flash scope in Spring? Since Spring 3.1+, RedirectAttributes  can be used for the same purpose. See  http://www.tikalk.com/java/redirectattributes-new-feature-spring-mvc-31

Spring bean config XML, Java config and more

1. XML-based metadata This is typical bean definition written in XML:     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">         <property name="dataSource" ref="dataSource"/>     </bean>    <jee:jndi-lookup id="dataSource" jndi-name="java:databaseName"/> Or     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">         <property name="dataSource" ref="dataSource"/>     </bean>     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">         <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>         <property name="url" value="jdbc:jtds:sqlserver://host_name/database_name;schema=dbo"/>         <property name="username" value="dummy"/...

Spring - context:annotation-config 与 context:component-scan 的区别与使用

<context:annotation-config> is used to activate annotations in beans already registered in the application context (no matter if they were defined with XML or by package scanning <context:component-scan> can also activate annotations in beans but also scans packages to find and register beans within the application context. To use annotations like @Required, @Autowired etc you need at least <context:annotation-config> that is because "annotations are a nice feature but by themselves they do nothing whatsoever. They just annotate stuff. You need a processing tool to find the annotations and do something with them. <context:annotation-config> to the rescue. This activates the actions for the annotations that it finds on the beans defined in the same application context where itself is defined." But since <context:annotation-config> only works with beans that has already been registered. If we don't manually register those beans in ...

Spring 3 MVC 静态资源 404问题

在web.xml配置servlet-mapping的时候,如果url-pattern设置为“/” (如下),很多人都会遇到导入js,css,图片等静态资源出现Firefox调试窗口会报出的404错误,而你的确也不能访问那些资源. 大致有3种方法,就是在jsp页面中导入静态资源的时候需要用 标签。 例如: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 这里的c:url中 value的值也是需要特别注意到地方,见下面3种方法详细说明: 方法1. 修改web.xml文件,增加对静态资源的url映射 如: default *.js default *.css 在web.xml中添加好配置后,在jsp页面就可以引用这些静态资源了,但需要用 , 如: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 这里还需要说明的是:这种方法不能访问WEB-INF目录下的静态资源,也就是js目录必须是web根(可能是webapp,webContent等)目录下,否则是不能引用的; 如果放在WEB-INF目录下,即使你使用 也是会出现404错误的。 百度时发现:以下各容器的default servlet名字,而且还提到静态资源servlet映射需要写在dispatcherServlet的前面;我在Jboss-eap-5.1中测试过,前后没有关系;所以可能是容器或者版本的关系吧。 Tomcat, Jetty, JBoss, and GlassFish  默认 Servlet的名字 -- "default" Google App Engine 默认 Servlet的名字 -- "_ah_default" Resin 默认 Servlet的名字 -- "resin-file" WebLogic 默认 Servlet的名字  -- "FileServlet" WebSphere ...