spring-4

Spring @Conditional based on a value in database table

╄→гoц情女王★ 提交于 2021-02-11 14:15:54
问题 Condition evaluation depends on a value provided in data base table @Component public class XYZCondition implements Condition{ @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { //based on value defined in DB should return true/false } } As Condition is executing very early, unable to fetch db value is there any alternate way to achieve this ? 回答1: Database values can be changed during application work, while it doesn't seem a good idea to reload

What is the equivalent of die() in Spring?

二次信任 提交于 2021-02-11 13:00:17
问题 In PHP there is the die("some message"); to write output and stop the execution of the script. So is there an equivalent in Spring mvc ( in Controller and in the JSP ) ? 回答1: There is no reason to have something like die() in Java/JSPs. JSPs should be used as a pure view technology. It should just generate HTML. Not try to access a database, read files or whatnot. That is the job of a controller, written in Java Use System.exit(0); to exit the java code. Keep a note this will stop the JVM

How to redirect page after ajax complete?

Deadly 提交于 2021-01-29 03:57:42
问题 My ajax is performing successfully because it deletes the row from database : @Controller ... @ResponseBody @RequestMapping(value = "/ajaxDeleteUser", method = RequestMethod.POST) public ModelAndView ajaxDelUser(HttpServletRequest request) { int userId = Integer.parseInt(request.getParameter("id")); userDao.delete(userId); return new ModelAndView("redirect:/"); } ... At the view : <c:url value="/" var="home" scope="request" /> $.ajax({ data: {"id":data}, type: "POST", url: "${home}"+

How to redirect page after ajax complete?

半城伤御伤魂 提交于 2021-01-29 03:50:20
问题 My ajax is performing successfully because it deletes the row from database : @Controller ... @ResponseBody @RequestMapping(value = "/ajaxDeleteUser", method = RequestMethod.POST) public ModelAndView ajaxDelUser(HttpServletRequest request) { int userId = Integer.parseInt(request.getParameter("id")); userDao.delete(userId); return new ModelAndView("redirect:/"); } ... At the view : <c:url value="/" var="home" scope="request" /> $.ajax({ data: {"id":data}, type: "POST", url: "${home}"+

Spring JSON Response: Serialize only the response object content (do not Wrap Root Value)

∥☆過路亽.° 提交于 2021-01-28 21:26:08
问题 In my application every restful service returns the following object, which indicate whether the request terminated with success or an error, it contains an optional error message and, of course, the object: public class JSONResponse { public boolean success = true; public String errmsg = ""; public Object body; /* getter/setter */ } When I call the restful service, I get the following JSON: { "JSONResponse":{ "success":true, "errmsg":"", "body":[] } } Unfortunately, I already have the client

Priority of Various Sources in PropertySources

无人久伴 提交于 2021-01-21 04:17:24
问题 Spring has introduced a new annotation @PropertySources for all classes marked as @Configuration since 4.0 . It takes different @PropertySource as argument. @PropertySources({ @PropertySource("classpath:application.properties"), @PropertySource("file:/tmp/application.properties")}) What I am interested is knowing is the ordering in case of conflict in values for the same key present in multiple properties file. I have not seen any documentation related to this that specifies an ordering. I

Spring 4 WebSocket Remote Broker configuration

六眼飞鱼酱① 提交于 2020-01-28 20:59:30
问题 I managed to create simple Websocket application with Spring 4 and Stomp. See my last question here Then I tried to use remote message broker(ActiveMQ). I just started the broker and changed registry.enableSimpleBroker("/topic"); to registry.enableStompBrokerRelay("/topic"); and it worked. The question is how the broker is configured? I understand that in this case the application automagicaly finds the broker on localhost:defaultport, bu what if I need to point the app to some other broker

Spring 4 WebSocket Remote Broker configuration

两盒软妹~` 提交于 2020-01-28 20:55:40
问题 I managed to create simple Websocket application with Spring 4 and Stomp. See my last question here Then I tried to use remote message broker(ActiveMQ). I just started the broker and changed registry.enableSimpleBroker("/topic"); to registry.enableStompBrokerRelay("/topic"); and it worked. The question is how the broker is configured? I understand that in this case the application automagicaly finds the broker on localhost:defaultport, bu what if I need to point the app to some other broker

Get rid of first View Controller with Spring 4 and AngularJS

十年热恋 提交于 2020-01-17 03:38:25
问题 I use RestController to fetch data with AngularJS , but still I need regular controller to load index.html : @Controller public final class LayoutController { @RequestMapping(value = "/") public String getIndexPage() { return "/resources/index"; } } Every other controllers are RestController s. If index file has jsp extension, I don't neeed LayoutController , but when it is html it is needed. This is my dispatcher config: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www

Initialize Quartz scheduler with Spring 4/Boot

给你一囗甜甜゛ 提交于 2020-01-15 10:59:06
问题 I have a Spring 4 application with Spring Boot - There is no WEBINF/web.xml file, however, I'd like to initialize a Quartz 2.2.1 scheduler on application startup. However, all the examples using QuartzInitializerServlet define the settings in the web.xml file. Can I add these configurations to my application startup configuration? @Configuration @ComponentScan @EnableAutoConfiguration public class Application { @Bean public DataSource dataSource() { DriverManagerDataSource ds = new