我在我的应用程序中使用Sping MVC并为DAO编写JUnit测试用例.当我运行测试时,我收到错误:java.lang.ClassNotFoundException: javax.servlet.ServletContext.
在堆栈跟踪中,我看到此错误是在此期间引起的getApplicationContext.在我看来applicationContext,我还没有定义任何servlet.Servlet映射只在这里完成,web.xml所以我不明白为什么我会收到这个错误.
这是我的applicationContext.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
xmlns:tx="http://www.springframework.org/schema/tx">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="user" value="username"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/myWorld_test</prop>
<prop key="hibernate.connection.username">username</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.myprojects.pojos</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" …Run Code Online (Sandbox Code Playgroud) 我期望下面两个脚本的输出相同.
但是当我执行脚本1时,我没有在按钮上获得图像.但是,脚本2运行良好.
脚本1
from Tkinter import *
class fe:
def __init__(self,master):
self.b=Button(master,justify = LEFT)
photo=PhotoImage(file="mine32.gif")
self.b.config(image=photo,width="10",height="10")
self.b.pack(side=LEFT)
root = Tk()
front_end=fe(root)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
脚本2
from Tkinter import *
root=Tk()
b=Button(root,justify = LEFT)
photo=PhotoImage(file="mine32.gif")
b.config(image=photo,width="10",height="10")
b.pack(side=LEFT)
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 我有一个基于gradle的独立项目.当我进行gradle构建时,jar在build/libs下生成.如何从命令行运行此可执行jar?我尝试过:java -cp build/libs/foo.jar full.package.classname但是对于导入的类,我得到noClassFoundException.如何将依赖jar作为classpath的一部分?
我是Java编程的新手.我有一个用例,我必须并行执行2个db查询.我班级的结构是这样的:
class A {
public Object func_1() {
//executes db query1
}
public Object func_2() {
//executes db query1
}
}
Run Code Online (Sandbox Code Playgroud)
现在我在同一个类中添加另一个函数func_3,它调用这两个函数,但也确保它们并行执行.为此,我正在使用callables和期货.这是以这种方式使用它的正确方法吗?我将此变量存储在临时变量中,然后使用它来调用func_3中的func_1和func_2(我不确定它是否正确).或者还有其他方法可以处理这类案件吗?
class A {
public Object func_1() {
//executes db query1
}
public Object func_2() {
//executes db query1
}
public void func_3() {
final A that = this;
Callable call1 = new Callable() {
@Override
public Object call() {
return that.func_1();
}
}
Callable call2 = new Callable() {
@Override
public Object call() {
return that.func_2();
}
} …Run Code Online (Sandbox Code Playgroud) 子div是否有可能不继承父div的背景颜色而是继承body标签的背景?
例如:
<body>
<div id="main">
<div id="sub">
some content
</div>
</div>
</body>
body {
background-image: url("blah");
}
#main {
background-color: white;
}
Run Code Online (Sandbox Code Playgroud)
div sub总是将background-color继承为白色.但是有没有一种方法(解决方法)在CSS中指定sub不应该继承白色?我读到CSS不允许这样做但是有没有解决这个问题?
我正在尝试构建一个java websocket服务器.我写了一个简单的服务器端点:
@ServerEndpoint(value = "/test")
public class EndPoint {
static Queue<Session> queue = new ConcurrentLinkedQueue<Session>();
public static void send(int a, int b) {
try {
for(Session session : queue) {
session.getBasicRemote().sendText("a = " + a + ",b=" + b);
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
@OnOpen
public void openConnection(Session session) {
queue.add(session);
}
@OnClose
public void closeConnection(Session session) {
queue.remove(session);
}
@OnError
public void error(Session session, Throwable t) {
queue.remove(session);
}
}
Run Code Online (Sandbox Code Playgroud)
我的web.xml看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<web-app …Run Code Online (Sandbox Code Playgroud) 根据LinkedIn文档,我发现我们无法使用移动访问令牌来进行LinkedIn提供的REST API调用.我有一个用例,在我的移动应用程序中,我使用LinkedIn的移动SDK登录到linkedin,我需要在后端获取某些数据,如登录用户的连接等.理想情况下,这应该在后端而不是移动设备上完成,因为我不希望从应用程序到我们的服务器进行太多调用.这有什么工作要做吗?
我是php的新手.是否有任何函数可以匹配给定字符串中的模式,并返回该字符串中模式开头的索引?例如:if $pattern = '/abcd/',$string = 'weruhfabcdwuir'那么函数应该返回6,因为6是'abcd'in的起始索引$string