更新:不知何故,经过另一轮调整和重新部署后,localhost:8080/ping-1.0/ping开始工作.配置文件仍然如下.我希望在不知情的情况下知道我修复了什么,但现在已经解决了.
我已经和它搏斗了几天,尝试了我在这里和其他地方看过的各种解决方案,但没有任何效果.我在Tomcat中部署了一个Spring MVC控制器,但无法访问它.
工具:
Spring 3.2.0
Tomcat 7
Java 1.6
弹簧控制器:
@Controller
public class PingController {
@RequestMapping("/ping")
public String ping (Model model) throws Exception {
System.out.println("ping ping ping");
String s = (new Date()).toString();
model.addAttribute("message", s);
return "ping";
}
}
Run Code Online (Sandbox Code Playgroud)
web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>ping</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ping-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ping</servlet-name>
<url-pattern>/ping</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
平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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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">
<context:component-scan …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用Spring和Hibernate的组合,并希望测试DAO方法Save和Delete方法.
daoFoundation是一个通过hibernateSession创建的包装类.
@Override
public String createSubject(Subject subject) {
String subjectId = (String) daoFoundation.save(subject);
return subjectId;
}
Run Code Online (Sandbox Code Playgroud)
这是我在JUnit中使用SpringJunit4ClassRunner编写的内容我在SetupMethod中
创建了主题对象.
@Test
public void createSubjectTest(){
subjectDao.createSubject(subject);
assertNotNull(hassSubjectSelection.getId());
}
Run Code Online (Sandbox Code Playgroud)
这是否足够,还是我需要在我的测试类中另外编写任何内容?
我正在使用GSON来验证JSON格式的字符串:
String json="{'hashkey':{'calculatedHMAC':'f7b5addd27a221b216068cddb9abf1f06b3c0e1c','secretkey':'12345'},operation':'read','attributes':['name','id'],'otid':'12'}";
Gson gson=new Gson();
Response resp = new Response();
RequestParameters para = null;
try{
para = gson.fromJson(json, RequestParameters.class);
}catch(Exception e){
System.out.println("invalid json format");
}
Run Code Online (Sandbox Code Playgroud)
它做得很好但是当我删除下面的引号时,我已经从hashkey中删除了:
"{hashkey':{'calculatedHMAC':'f7b5addd27a221b216068cddb9abf1f06b3c0e1c','secretkey':'12345'},operation':'read','attributes':['name','id'],'otid':'12'}"
Run Code Online (Sandbox Code Playgroud)
它仍然将它验证为正确的JSON格式,并且不会抛出任何异常而不会进入catch体.这样做的原因是什么?我该如何解决这个问题?
RequestParameters类:
public class RequestParameters {
HashKey hashkey;
String operation;
int count;
int otid;
String[] attributes;
}
Run Code Online (Sandbox Code Playgroud) 我有一个条件,我需要从队列中读取数据并相应地处理它.因此我为此目的使用apache-camel.
现在我的Camel配置如下:
applicationContext.xml中
<camel:camelContext id="camel-server">
<camel:package>com.sorc.processor.route</camel:package>
<camel:jmxAgent id="agent" createConnector="true" />
</camel:camelContext>
Run Code Online (Sandbox Code Playgroud)
FeedProcessorRoute.java
public class FeedProcessorRoute extends RouteBuilder{
private @Value("${activemq_feed_observer_queue_name}") String activemqQueueName;
@Override
public void configure() throws Exception {
from("amq:" + activemqQueueName + "?exchangePattern=InOut&preserveMessageQos=true")
.routeId("id1") // Set the routeId to the class name. The routeId is printed when logging.
.process(this.feedProcessorTrigger)
.log("The FeedProcessor route has finished\n\n"));
}
Run Code Online (Sandbox Code Playgroud)
FeedProcessorTrigger.java
public class FeedProcessorTrigger implements Processor{
@Override
public void process(Exchange exchange) throws Exception {
//I have added my processing logic here
}
}
Run Code Online (Sandbox Code Playgroud)
当我在tomcat中部署我的战争时,我得到以下错误
15:06:24.602 …Run Code Online (Sandbox Code Playgroud) 运行 import P4 时出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python35\lib\site-packages\P4.py", line 410, in <module>
import P4API
ImportError: DLL load failed: The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)
我在网上查看但找不到有帮助的东西。
当我使用Spring Data Redis进行注入时redisTemplate,会发生以下错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisTemplate' defined in com.worktime.configure.JpaConfigurationTest: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.serializer.support.DeserializingConverter.<init>(Ljava/lang/ClassLoader;)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 more
Caused by: java.lang.NoSuchMethodError: org.springframework.core.serializer.support.DeserializingConverter.<init>(Ljava/lang/ClassLoader;)V
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.<init>(JdkSerializationRedisSerializer.java:53)
at org.springframework.data.redis.core.RedisTemplate.afterPropertiesSet(RedisTemplate.java:117)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 40 more
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
@Bean
public …Run Code Online (Sandbox Code Playgroud) 最近我正在开发一个基于raspberrypi 2b +的设备,它连接到mpu9250(我自己焊接).
我可以正确读取9轴数据,但我注意到每个数据输入具有不同的时间差:
该图显示了每两个数据之间的时间差.但我已经使用QTimer确保我的代码每隔10ms读取一次mpu9250.
所以我在RaspberryPi 2b +上尝试了这个代码:
import time
import matplotlib.pyplot as plt
time_arr = []
for i in range(5000):
t0 = time.time()
print "K"
t1 = time.time() - t0
time_arr.append(t1)
plt.plot(time_arr)
plt.show()
Run Code Online (Sandbox Code Playgroud)
结果:
即使这些简单的代码仍然在图表上显示高峰,它让我失望......
任何人都可以帮助我解决这些问题或解释发生了什么?
我已经设置了Web服务器并基于HTTP请求,并且需要以其他用户身份执行脚本。
因此,关于这一点,我可以按照需要的用户身份运行HTTP吗?
或者我可以非交互方式提供密码,并在bat文件的第一行中包含以下内容。
runas /user:dmn1\user1 cmd
Run Code Online (Sandbox Code Playgroud) 我不知道如何在数据访问层上应用单元测试.我总是想知道是否应该测试数据访问层.在我的公司,我们有稳定的数据库来存储单元测试数据和测试数据访问层,方法是运行数据访问对象并检查它们从稳定数据库中获取的数据.
为了通过单元测试,稳定数据库中的数据不再被修改.我认为有更好的解决方案.如果我没有弄错,模拟对象不能对SQL语句和ResultSet映射执行测试.
对DAO进行单元测试的最佳方法是什么?使用TDD有更好的方法吗?
我在使用ZF2在视图中渲染表单时遇到问题.我正在按照"Zend Framework 2.0 by Example"一书的说法.问题是,在对应视图中呈现表单时,会弹出以下错误:
A plugin by the name "form" was not found in the plugin manager Zend\View\HelperPluginManager
Run Code Online (Sandbox Code Playgroud)
我在这里和ZF论坛都遇到了所有类型的错误,但是我找不到我的问题的答案,所以我都选择了.
这是相关文件:
// Module.php
namespace Users;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements AutoloaderProviderInterface, ConfigProviderInterface {
public function getAutoloaderConfig() {
return [
'Zend\Loader\ClassMapAutoloader' => [
__DIR__ . '/autoload_classmap.php',
],
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
],
],
];
}
public function getConfig() {
return include __DIR__ . '/config/module.config.php';
}
}
//module.config.php
namespace Users;
return …Run Code Online (Sandbox Code Playgroud) java ×5
spring ×4
php ×2
python ×2
apache-camel ×1
batch-file ×1
dao ×1
forms ×1
gson ×1
hibernate ×1
jedis ×1
jms ×1
json ×1
junit ×1
p4python ×1
performance ×1
raspberry-pi ×1
raspbian ×1
redis ×1
spring-mvc ×1
time ×1
tomcat ×1
unit-testing ×1
zend-form ×1