Package name does not correspond to the file path是什么原因
使用IDEA 2018 Spring框架,运行测试用例报错
Error:(3, 1) java: 需要class, interface或enum
其中错误行的提示信息是:
Package name 'com.bjpowernode.ba01' does not correspond to the file path 'com.bjpowernode.service'
代码如下:
package com.bjpowernode.ba01;
package com.bjpowernode.service;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.*;
public class AppTest {
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
@Test
public void test01(){
System.out.println( "Hello World!" );
String config ="applicationContext.xml";
//创建spring容器对象,根据spring配置文件的位置,使用接口的不同实现类
//如果spring的配置文件是在类路径(classpath),使用ClassPathXmlApplicationContext
ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
SomeService service = (SomeService)ctx.getBean("someService");
service.doSome();
}
@Test
public void test02(){
String config = "ba01/applicationContext.xml";
ApplicationContext ctx = new ClassPathXmlApplicationContext(config);
SomeService so = (SomeService)ctx.getBean("someService");
System.out.printf("SomeServiece:"+so);
}
}
目录结构