【发布时间】:2017-09-29 08:12:47
【问题描述】:
我在一个简单的 spring 示例中添加了一个 junit 测试,但它无法自动装配我编写的 json 服务。
要在春季 JUnit 测试中进行自动装配需要什么?
要尝试失败的项目...
git clone https://bitbucket.org/oakstair/spring-boot-cucumber-example
cd spring-boot-cucumber-example
./gradlew test
提前致谢!
应用
@SpringBootApplication
@ComponentScan("demo")
public class DemoApplication extends SpringBootServletInitializer {
服务接口
@Service
public interface JsonUtils {
<T> T fromJson(String json, Class<T> clazz);
String toJson(Object object);
}
服务实现
@Component
public class JsonUtilsJacksonImpl implements JsonUtils {
测试
@ContextConfiguration()
@RunWith(SpringJUnit4ClassRunner.class)
@ComponentScan("demo")
public class JsonUtilsTest {
@Autowired
private JsonUtils jsn;
【问题讨论】:
-
请将有问题的代码添加到此问题中
-
您可以通过克隆在 10 秒内获得!在这里粘贴的不是很多,而是很多...
-
@GunnarEketrapp 没有人有时间克隆你的项目......