我正在尝试使用Spring框架使用JUnit测试CRUD方法.下面的代码完美无缺
@Transactional
public class TestJdbcDaoImpl {
@SuppressWarnings("deprecation")
@BeforeClass
@Test
public static void setUpBeforeClass() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
JdbcDaoImpl dao = ctx.getBean("jdbcDaoImpl",JdbcDaoImpl.class);
Circle cicle = new Circle();
dao.insertCircle(new Circle(6,"e"));
}}
Run Code Online (Sandbox Code Playgroud)
但是,使用@RunWith(SpringJUnit4ClassRunner.class)的代码会给我一个错误
**2014年6月11日下午1:00:15 org.springframework.test.context.TestContextManager retrieveTestExecutionListeners信息:无法实例化TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener].指定自定义侦听器类或使默认侦听器类(及其所需的依赖项)可用.违规类:[javax/servlet/ServletContext]**
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring.xml")
@Transactional
public class TestJdbcDaoImpl {
@Autowired
private static JdbcDaoImpl dao;
@SuppressWarnings("deprecation")
@BeforeClass
public static void setUpBeforeClass() throws Exception {
Circle cicle = new Circle();
dao.insertCircle(new Circle(10,"e"));
}
Run Code Online (Sandbox Code Playgroud) 我的问题是在java中编译c ++文件.我试过执行c#,很好.这个用于编译c#的提取代码
ProcessBuilder launcher = new ProcessBuilder("gmcs","HelloWorld.cs");`
Run Code Online (Sandbox Code Playgroud)
但是,我的c ++代码
ProcessBuilder launcher =new ProcessBuilder("g++", "HelloWorld.cpp -o HelloWorld");
Run Code Online (Sandbox Code Playgroud)
返回错误= 2,没有这样的文件或目录指示我
launcher.directory(new File(path))
在两种情况下使用的路径
美好的一天!我在获取java线程的内存使用方面遇到了麻烦.我的研究把我带到了ThreadMxBean库.根据javadocThreadMXBean#setThreadAllocatedMemoryEnabled,应该有一个getThreadAllocatedBytes允许获取线程内存的方法.但是,我找不到这种类的方法,而存在上述文档中描述的其他方法.
示例getCurrentThreadCpuTime()并isThreadCpuTimeEnabled()显示在我的代码中.
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
class TwoThreadsTest {
public static void main (String[] args) throws Exception {
new Coding("Jamaica").start();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long b = threadBean.getCurrentThreadCpuTime();
boolean bool= threadBean.isThreadCpuTimeEnabled();
System.out.println(bool);
}
}
Run Code Online (Sandbox Code Playgroud)