小编dan*_*emp的帖子

如何将application.properties中的值赋给静态变量?

我正在使用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");

它给出了同样的错误.

java spring spring-boot

23
推荐指数
3
解决办法
6万
查看次数

使用 jQuery 将对象数组传递给 Spring MVC 控制器

我有一个如下的 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)

ajax jquery spring json spring-mvc

0
推荐指数
1
解决办法
5741
查看次数

标签 统计

spring ×2

ajax ×1

java ×1

jquery ×1

json ×1

spring-boot ×1

spring-mvc ×1