Java AnjularJs与Spring boot的集成

Java AnjularJs与Spring boot的集成,java,angularjs,spring,hibernate,Java,Angularjs,Spring,Hibernate,我需要在java类中调用index()方法。但我试过这种方法,但它不起作用 它将转到console.log('coming here…)在controller.js中,之后http路径无法识别 @RestController public class DatumBoxShedule { @Autowired private DatumService datumService; @RequestMapping(value = "/loadIndex", produces

我需要在java类中调用
index()
方法。但我试过这种方法,但它不起作用

它将转到
console.log('coming here…)
controller.js
中,之后http路径无法识别

@RestController
public class DatumBoxShedule {

    @Autowired
    private DatumService datumService;

    @RequestMapping(value = "/loadIndex", produces = MediaType.APPLICATION_JSON_VALUE,  method = RequestMethod.GET)
    public String index() throws IOException {

    }
}
controller.js

app.controller('datumBoxShedule', function($scope, $http) {
    $scope.newTodo = {};

    $scope.loadIndex = function(){
         console.log('coming here....');
        $http.get('loadIndex')
        .success(function(data, status, headers, config) {
            $scope.todos = data;
         })
        .error(function(data, status, headers, config) {
              alert('Error loading DatumBoxShedule');
        });
    };

    $scope.loadIndex();
});

角度项目是Spring项目的一部分吗

其他映射是否正常工作(换句话说:REST服务是否正在运行)? 如果没有:您的DependedEncies中是否有类似Tomcat的嵌入式容器

例如,您可以将Tomcat的依赖项添加到项目中:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

org.springframework.boot
SpringBootStarterWeb

我想,问题不在anujularjs中。问题在春天

我的ComponentScan坏了

包main.java.datumbox

@配置 @SpringBoot应用程序 @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,hibernatejpaaautoconfiguration.class}) @组件扫描({“main.java.datumbox.service.impl”、“main.java.datumbox.controller”、“main.java.datumbox.service”}) 公共类应用程序{

public static void main(String[] args) throws Exception {

    SpringApplication.run(Application.class,args);

}
}

包main.java.datumbox.service.impl

公共类DatumServiceImpl{

@Autowired(required = true)
DatumDataRepository datumDataRepository;
}

包main.java.datumbox.controller

@RestController 公共类DatumBoxController{

@Autowired
private DatumService datumService;

@Autowired
private DatumServiceImpl datumServiceImpl;


@RequestMapping( value = "/loadIndex" , produces = MediaType.APPLICATION_JSON_VALUE,  method = RequestMethod.GET)
public String index() throws IOException {

}
}

包main.java.datumbox.service

@服务 公共类数据服务{

@Autowired
HitApiService hitApiService;
}

错误就要来了


应用程序无法启动


说明:

main.java.datumbox.controller.DatumBoxController中的字段datumServiceImpl需要找不到类型为“main.java.datumbox.service.impl.datumServiceImpl”的bean

行动:


考虑在配置中定义类型为“main.java.datumbox.service.impl.DatumServiceImpl”的bean。

尝试检查状态代码,它可能是404,这意味着您需要提供绝对路径:
$http.get('/loadIndex')…
。您可以直接从浏览器访问Rest API端点,或者使用浏览器扩展(如Postman)来检查请求/响应。我尝试了$http.get('/loadIndex'),但仍然出现相同的错误。后端Rest服务的基本上下文是什么?通常您会有类似
http://host:port/*myApp*/loadIndex
我的上下文是您能否从浏览器的调试控制台提供错误消息?