我需要从我的控制器返回JSON/XML数据.从我发现的,我需要@ResponseBody在我的方法中,为此我需要<mvc:annotation-driven>启用.我尝试了各种RnD,但仍然卡住了!:(
显然我的问题在于我的servlet.xml文件(模式没有得到验证!)我正在使用Spring 3.1.1并在我的类路径中明确地放入了spring-mvc-3.1.1.jar.
这是我的servlet-context文件sample-servlet.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc-3.1 http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.sample.controller"/>
<mvc:annotation-driven/>
<!--Use JAXB OXM marshaller to marshall/unmarshall following class-->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="xmlViewer"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.sample.model.SampleClass</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="viewResolvers">
<list>
<bean 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>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我的控制器类看起来像这样:
@Controller
public class XmlController {
@RequestMapping(value="/getXml",method …Run Code Online (Sandbox Code Playgroud) 在我的程序中,创建了一个fClasses固定长度[7]的对象数组,每个对象都是一个FClass包含3 Strings,an int和a的类int[].这些值从.txt文件中读取,并根据其值添加到数组的特定索引中int..txt文件中的条目较少,然后数组中有索引,因此数组最终看起来像这样:
fClasses[0] { str1, str2, str3, int1, int [] {1,2,3,4,5}}
fClasses[1] { str1, str2, str3, int1, int [] {1,2,3,4,5}}
fClasses[2] { str1, str2, str3, int1, int [] {1,2,3,4,5}}
fClasses[3] null
fClasses[4] null
fClasses[5] { str1, str2, str3, int1, int [] {1,2,3,4,5}}
fClasses[6] { str1, str2, str3, int1, int [] {1,2,3,4,5}}
Run Code Online (Sandbox Code Playgroud)
在稍后的节目,我需要的基础上平均的数组排序ints的int[].我有一个工作方法来返回这个,但当我尝试使用数组排序时compareTo,Arrays.sort我得到一个很长的错误列表,从这些开始:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.util.ComparableTimSort.countRunAndMakeAscending(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud) 在将单元测试事后写入另一个项目创建的代码时,我遇到了如何模拟绑定到控制器的验证器的问题initBinder?
通常我会考虑确保我的输入是有效的,并在验证器中进行一些额外的调用,但在这种情况下,验证器类与通过一些数据源进行检查相结合,这一切都变得非常混乱.耦合可以追溯到一些使用的旧公共库,并且超出了我当前工作的范围来修复所有这些库.
起初我试图使用PowerMock模拟验证器的外部依赖关系并模拟静态方法,但最终遇到一个类,在创建类时需要数据源并且没有找到解决方法.
然后我尝试使用普通的mockito工具模拟验证器,但这也不起作用.然后尝试在mockMvc调用中设置验证器,但这不会注册@Mock验证器的注释.最后遇到了这个问题.但由于validator控制器本身没有字段,因此也失败了.那么,我该如何解决这个问题呢?
验证器:
public class TerminationValidator implements Validator {
// JSR-303 Bean Validator utility which converts ConstraintViolations to Spring's BindingResult
private CustomValidatorBean validator = new CustomValidatorBean();
private Class<? extends Default> level;
public TerminationValidator(Class<? extends Default> level) {
this.level = level;
validator.afterPropertiesSet();
}
public boolean supports(Class<?> clazz) {
return Termination.class.equals(clazz);
}
@Override
public void validate(Object model, Errors errors) {
BindingResult result = (BindingResult) errors;
// Check domain object against …Run Code Online (Sandbox Code Playgroud) 今天开始在办公室学习Spring Test MVC框架,它看起来很方便,但是直接面对一些严重的麻烦.花了几个小时谷歌搜索,但找不到与我的问题有关的任何事情.
这是我非常简单的测试类:
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = WebAppContext.class)
public class ControllerTests {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = webAppContextSetup(wac).build();
}
@Test
public void processFetchErrands() throws Exception {
mockMvc.perform(post("/errands.do?fetchErrands=true"))
.andExpect(status().isOk())
.andExpect(model().attribute("errandsModel", allOf(
hasProperty("errandsFetched", is(true)),
hasProperty("showReminder", is(false)))));
}
}
Run Code Online (Sandbox Code Playgroud)
测试到达以下控制器,但if由于未正确授权,因此在第一个条款上失败.
@RequestMapping(method …Run Code Online (Sandbox Code Playgroud) 我可以使用oepe 12.1.1.1.1将我的web-app从Eclipse Indigo 3.7.2发布到Oracle Weblogic 12c(12.1.1)AdminServer
但是,使用oepe 12.1.2.2导入到Eclipse Kepler 4.3.1中的完全相同的web-app无法使用以下(相当完善的例程)异常发布,并且我试图找出原因?...
NameNotFoundException:尝试查找'jdbc.oraclexe'时没有找到子上下文'jdbc'.解决 ''; 剩下的名字'jdbc/oraclexe']; 链接剩余名称:'jdbc/oraclexe'
Weblogic 12c数据源肯定是可用的,我必须假设它正确配置,因为应用程序部署并运行时从Indigo发布没有任何问题.
我还假设applicationContext.xml中的映射,web.xml和weblogic.xml都是正确的,因为从Indigo发布时没有问题.映射如下......
SRC \主\ web应用\ WEB-INF \弹簧\ applicationContext.xml中
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/oraclexe" />
</bean>
Run Code Online (Sandbox Code Playgroud)
SRC \主\ web应用\ WEB-INF\web.xml中
<resource-ref>
<description>Oracle Weblogic Connection Pool (oraclexe)</description>
<res-ref-name>jdbc/oraclexe</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>jdbc/oraclexe</mapped-name>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
建立\ weboutput\WEB-INF\weblogic.xml中
<resource-description>
<res-ref-name>jdbc/oraclexe</res-ref-name>
<jndi-name>oraclexe</jndi-name>
</resource-description>
Run Code Online (Sandbox Code Playgroud)
我想知道weblogic.xml是否在部署期间不可用(即它没有被复制到src\main\webapp\WEB-INF文件夹)而不是jndiName/resource-ref/res之间的映射问题-ref-name自己?我已经尝试将weblogic.xml直接放在src\main\webapp\WEB-INF文件夹中,但我得到了相同的异常.
我唯一的另一个想法是Indigo oepe 12.1.1.1.1很高兴发布到Weblogic 12.1.1但Kepler oepe 12.1.2不是,我应该发布到Weblogic 12.1.2服务器?
我正在努力教自己红宝石并解决工作中的问题.我的最终目标是从API中提取JSON响应中的许多字段中的三个,操作并转储到CSV以进行执行报告.
JSON的结构是:
{
"status": 200,
"data": {
"total": 251,
"alerts": [
{
"dataPoint": "x",
"ackedBy": "x",
"dataSourceInstance": "x",
"dataSource": "x",
"host": "x",
"endOn": 0,
"ackedOn": 1385085190,
"dataSourceInstanceId": 588384,
"hostId": 935,
"type": "alert",
"dataSourceId": 694,
"ackedOnLocal": "2013-11-21 17:53:10 PST",
"id": 6170384,
"startOn": 1385084917,
"thresholds": "!= 1 1 1",
"endOnLocal": "",
"level": "error",
"ackComment": "x",
"value": "No Data",
"hostDataSourceId": 211986,
"acked": true,
"hostGroups": [{
"alertEnable": true,
"createdOn": 1362084592,
"id": 21,
"parentId": 78,
"description": "",
"appliesTo": "",
"name": "2600hz",
"fullPath": "x"
}],
"startOnLocal": …Run Code Online (Sandbox Code Playgroud) 我们有一个解决方案,我们的UI项目通过使用EJB客户端依赖项包含了大量业务服务.Maven上的问题在于,即使客户端.jar通常包含大约1-2个类,它们也会带来整个服务应用程序的完整依赖性堆栈.这可能会有点难看,当.ear文件开始增长到50-100Mb pop 并且由于不相关的依赖性偷偷进入UI应用程序时不时出现麻烦的错误.
当然,我们总是可以排除客户端上的依赖关系,但是我们必须使用这些服务为每个客户端项目编写相同的一行,这是很多不必要的重复.此外,人们提出了最奇怪的错误消息并使用大量时间跟踪它们,然后再记得提到它们包含一些客户端jar并且没有检查它带来了什么额外的依赖性.
例:
<dependency>
<groupId>fi.path.to.service</groupId>
<artifactId>customermanagement-common</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>fi.path.to.service</groupId>
<artifactId>customermanagement-service</artifactId>
<classifier>client</classifier>
<exclusions>
<exclusion>
<groupId>fi.path.to.dependency</groupId>
<artifactId>internal-dependency-#1</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.castor</groupId>
<artifactId>castor</artifactId>
</exclusion>
<exclusion>
<groupId>fi.path.to.dependency</groupId>
<artifactId>internal-dependency-#2</artifactId>
</exclusion>
<exclusion>
<artifactId>internal-dependency-#3</artifactId>
<groupId>fi.path.to.dependency</groupId>
</exclusion>
<exclusion>
<artifactId>internal-dependency-#4</artifactId>
<groupId>fi.path.to.dependency</groupId>
</exclusion>
<exclusion>
<artifactId>internal-dependency-#5</artifactId>
<groupId>fi.path.to.dependency</groupId>
</exclusion>
<exclusion>
<artifactId>castor-xml</artifactId>
<groupId>org.codehaus.castor</groupId>
</exclusion>
<exclusion>
<artifactId>castor-codegen</artifactId>
<groupId>org.codehaus.castor</groupId>
</exclusion>
<exclusion>
<artifactId>castor-xml-schema</artifactId>
<groupId>org.codehaus.castor</groupId>
</exclusion>
<exclusion>
<artifactId>internal-dependency-#6</artifactId>
<groupId>fi.path.to.dependency</groupId>
</exclusion>
</exclusions>
<version>2.6</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这只是一个服务客户端被包含在内,想象在几个不同的应用程序中有几个并且你得到了图片,每次写入所有排除非常烦人并且项目POM开始变得相当漫长.
我会将依赖项标记为已提供,但是如果它们不存在,则会有一些依赖项在运行时崩溃.比如那些包含另一个带有外部Exception类的应用程序的服务调用,这不是出于某种原因而包含在服务项目中,并且如果不存在则会在运行时导致ClassNotFoundException.
因此,我知道通过在maven-ejb-plugin上使用pom.xml规范,可以在ejb客户端生成期间排除/包含类,但是有没有办法排除依赖项?
在node.js v6.0.0中
function testlet() {
let a = 0;
for (var i = 0; i < 100000000; i++) {}
}
function testlet2() {
for (var i = 0; i < 100000000; i++) {}
let a = 0;
}
console.time('let');
testlet();
console.timeEnd('let');
console.time('let2');
testlet2();
console.timeEnd('let2'); Run Code Online (Sandbox Code Playgroud)
如何let在代码中的位置导致如此大的性能差异?
我们在SOAP服务中从WSDL/XSD生成POJO.我们如何在使用RESTful Web服务时生成POJO?
我需要书库的功能,为此我使用过:
Turn.js,用于flipbook效果(只有第3个版本正常工作,第4个版本不能使用它,如果有人与turn.js的第4个版本有类似的功能,那么请分享你的代码).
pdf.js,在客户端将PDF转换为HTML
这是我所遵循的参考链接.
我已经修改了一个动态使用该脚本的功能,它将PDF的路径添加到该功能中,并根据该链接,在弹出窗口中打开书籍.
这是JavaScript函数:
function display_book(path){
var url = path;
PDFJS.disableWorker = false;
PDFJS.getDocument(url).then(function(pdfDoc) {
numberOfPages = pdfDoc.numPages;
pdf = pdfDoc;
$('#book').turn.pages = numberOfPages;
$('#book').turn({acceleration: false,
pages: numberOfPages,
elevation: 50,
gradients: !$.isTouch,
// display: 'single',
when: {
turning: function(e, page, view) {
// Gets the range of pages that the book needs right now
var range = $(this).turn('range', page);
// Check if each page is within the book
for (page = range[0]; page<=range[1]; …Run Code Online (Sandbox Code Playgroud) java ×7
javascript ×2
spring ×2
spring-mvc ×2
unit-testing ×2
annotations ×1
arrays ×1
client ×1
compareto ×1
dependencies ×1
eclipse ×1
ejb ×1
jquery ×1
json ×1
let ×1
maven ×1
mockito ×1
node.js ×1
pdf ×1
rest ×1
ruby ×1
service ×1
sorting ×1
spring-3 ×1
web ×1
weblogic12c ×1
xml ×1