我们在服务层和视图层上下文配置之间有一个清晰的抽象,我们正在加载它们,如下所示.
Root application context:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
Web application context:
<servlet>
<servlet-name>lovemytasks</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/mmapp-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Run Code Online (Sandbox Code Playgroud)
现在我们正在尝试引入SPRING MVC TEST FRAMEWORK来测试我们的应用程序.
为此,我需要设置与我的真实Web应用程序相同的环境.
我怎样才能做到这一点 ?
我在我的测试中尝试了以下配置来加载两个上下文.
@ContextConfiguration(locations = { "classpath*:META-INF/spring/applicationContext*.xml",
"file:src/main/webapp/WEB-INF/spring/mmapp-servlet.xml" })
Run Code Online (Sandbox Code Playgroud)
但它错误地说出来了
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Duplicate <global-method-security> detected.
Run Code Online (Sandbox Code Playgroud)
我们在根应用程序上下文和Web应用程序上下文中定义了全局安全性.
注意:运行我的Web应用程序时,上述问题不会出现.它只在我运行Spring MVc测试时才会发生
我尝试删除我的全局安全性和一个地方,然后在运行我的测试时使用转换服务登陆错误.这告诫我,我没有像真正的Spring应用程序那样加载上下文.
现在,我想设置我的Spring MVC测试环境,以便像我的Spring Web应用程序环境一样使用或工作.任何人都可以建议我如何实现它?
我们有一个 Spring 绑定,它List使用 Spring 提供的默认转换器将字符串转换为s。
例如,如果我们a, b, c从表单推送,那么控制器会得到一个List带元素的:
我们不必在我们的代码中做任何特别的事情。
我在处理数据中的逗号时遇到问题。如果我在a, x,z, b , c这里提交x,z的实际上是一个字符串,但 Spring 转换器不知道这一点,并假定它是一个分隔符,并List像这样组成:
现在我来回答我的问题:
,提交表单时,我可以在数据中转义(逗号)吗?我使用此处指定的代码合并了两个excel文件
http://www.coderanch.com/t/614715/Web-Services/java/merge-excel-files
这个块应用我的合并单元格的样式
if (styleMap != null)
{
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook())
{
newCell.setCellStyle(oldCell.getCellStyle());
}
else
{
int stHashCode = oldCell.getCellStyle().hashCode();
XSSFCellStyle newCellStyle = styleMap.get(stHashCode);
if (newCellStyle == null)
{
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
styleMap.put(stHashCode, newCellStyle);
}
newCell.setCellStyle(newCellStyle);
}
}
Run Code Online (Sandbox Code Playgroud)
这一切都按预期工作,并在生成我的XSSFWorkbook方面做得很好.
我尝试打开时出现问题:
我看到下面的错误


我的错误报告包含在下面
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error072840_01.xml</logFileName>
<summary>Errors were detected in file 'XYZ.xlsx'</summary>
<repairedRecords summary="Following is a list of repairs:">
<repairedRecord>Repaired Records: Format from /xl/styles.xml part (Styles)</repairedRecord>
</repairedRecords>
</recoveryLog>
Run Code Online (Sandbox Code Playgroud)
毕竟这些我的表单打开很好,但没有样式.我知道要创建的样式数量有限制,并且已经计算了正在创建的样式,我几乎看不到创建的样式.我甚至知道这个问题的风格太多了.
不幸的是,POI支持仅优化HSSFWorkbook(Apache POI从工作簿中删除CellStyle)
如何缓解这个问题的任何帮助都会很棒.