我正在使用Spring MVC.我有一个UserService
带有@Service
很多静态变量的类注释.我想用application.properties文件中的值来实例化它们.
例如,在application.properties中我有: SVN_URL = http://some.url/repositories
然后在课堂上有: @Value("${SVN_URL}") private static String SVN_URL
我明白了 Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
我也试过了 @Autowired private static Environment env;
然后: private static String SVN_URL=env.getProperty("SVN_URL");
它给出了同样的错误.
我有一个如下的 POJO,它包含其他 POJO 的列表:
public class Commit {
private long revision;
private Date date;
private String author;
private String comment;
private String akuiteo;
private List<ChangedPath> changedPathList = new ArrayList<ChangedPath>();
//Getters, Setters and Constructor following
}
Run Code Online (Sandbox Code Playgroud)
我的控制器需要 3 个参数,其中一个是数组或提交列表:
@RequestMapping(value="/selectedCommits",method=RequestMethod.POST)
@ResponseBody
public List<Commit> getAllDependentCommits(@RequestParam("branch")String branch,
@RequestParam("tag")String tagName,@RequestParam(value="commits[]") Commit[] commits) throws IOException{
List<String> changedPaths=new ArrayList<String>();
List<Commit> dependentCommits=UserService.listAllCommits(branch, tagName, commits);
//UserService.createPatchFromSelectedCommits(branch, tagName, revisions);
return dependentCommits;
}
Run Code Online (Sandbox Code Playgroud)
我也试过:List<Commit> commits
而不是Commit[ ] commits
我使用 AJAX 从 jQuery 脚本调用控制器:
$("#buttonCommit").click(function(e){
console.log(branch);
console.log(tag);
console.log(selectedCommits);
$.ajax({ …
Run Code Online (Sandbox Code Playgroud)