Maven / Spring自动装配不起作用

时间:2015-08-13 07:30:13

标签: java spring maven

我遇到了一个错误:“预计至少有一个bean可以作为此依赖关系的autowire候选者” 我是Spring的新手。我运行了“mvn spring-boot:run”并拥有以下代码。

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
@RestController
public class GreetingController {
    @Autowired
    private MyServiceTest myServiceTest;
......
}

public class RemotePossessionServiceTest {
...
}

但是我仍然在myServiceTest上“预计至少有一个bean有资格作为此依赖关系的autowire候选者”错误。我的包名是“你好”。这是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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan base-package="hello" />
<bean id = "myServiceTest" class="hello.MyServiceTest"></bean>

这是web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     id="WebApp_ID" version="3.0">
  <display-name>RRRRR</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>

0 个答案:

没有答案