Spring Boot输出为无消息,错误(状态= 500)

时间:2019-11-04 15:18:36

标签: java spring-boot jena

spring Boot项目给我没有消息,输出为空!我知道此错误意味着我的代码有问题,但是我对本体和TDB还是那么陌生,请提供帮助!我试图将rdf文件中的所有个人都存储在TDB中,但找不到有用的答案!

Example.java

public class Example {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

ExampleController.java

@RestController
public class ExampleController {

    File file;
    Model model;
    InfModel infModel;
    Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
    Dataset dataset;
    QueryExecution qe;

    @RequestMapping("/getAll")
    public List getAllIndiv() { 
        List list = new ArrayList();
        try {
              String directory = "tdb" ;
               dataset = TDBFactory.createDataset(directory) ;
               dataset.begin(ReadWrite.READ) ;
              String uri ="http://example#";
              model = dataset.getNamedModel(uri);
              String source = "example.owl";
              FileManager.get().readModel(model, source);
            String a = "";
            String queryString = "\r\n"
                    + "PREFIX ns: <http://example#>"
                    + "PREFIX rdf: <http://example-syntax-ns#>" + "SELECT ?Individuals " + "WHERE {"
                    + "?Individuals rdf:type ns:Concept." + "}";
            Query query = QueryFactory.create(queryString);
            query.getQueryPattern();
             qe = QueryExecutionFactory.create(query, dataset);
            ResultSet results = qe.execSelect();
            ResultSetFormatter.out(results);
            while (results.hasNext()) {
                QuerySolution result = (results.next());
                RDFNode ind = result.get("Individuals");
                a = ind.asResource().getLocalName() + "";
                list.add(a);
            qe.close();
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }finally {

            if(model != null && dataset != null) {
                qe.close();
                dataset.commit();            
                model.close();
              dataset.end();
            }
        }
        return null;
    }   
}

0 个答案:

没有答案