spring-mvc

Spring MVC not logging all exceptions

≯℡__Kan透↙ 提交于 2021-02-07 06:49:13
问题 I have Spring MVC setup to log exceptions using commons logging, but find that some runtime exceptions aren't being logged. Here's my bean configuration for the default exception resolver provided by spring: <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">error</prop> </props> </property> </bean> 回答1: To get this to log most exceptions, I had to add the following line to my config

Spring MVC not logging all exceptions

旧巷老猫 提交于 2021-02-07 06:49:11
问题 I have Spring MVC setup to log exceptions using commons logging, but find that some runtime exceptions aren't being logged. Here's my bean configuration for the default exception resolver provided by spring: <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">error</prop> </props> </property> </bean> 回答1: To get this to log most exceptions, I had to add the following line to my config

Spring Transactional Annotation

心已入冬 提交于 2021-02-07 06:17:16
问题 I'm trying to get a better handle on the use of Spring's @Transactional attribute. I understand that it basically wraps the contents of the method marked as @Transactional in a transaction. Would it be appropriate to mark a service/business layer method as transactional, as opposed to the actual DAO method, as I have done here? Service Implementation public class UserServiceImpl implements UserServiceInt{ @Autowired private UserServiceDAO serviceDAO; @Override public User getUser(int id){

How to add basic auth to Autowired testRestTemplate in SpringBootTest; Spring Boot 1.4

夙愿已清 提交于 2021-02-07 06:17:03
问题 My OAuth integration test before Spring Boot 1.4 looked as follows(updates just to not use deprecated features): @RunWith(SpringRunner.class) @SpringBootTest(classes = { ApplicationConfiguration.class }, webEnvironment = WebEnvironment.RANDOM_PORT) public class OAuth2IntegrationTest { @Value("${local.server.port}") private int port; private static final String CLIENT_NAME = "client"; private static final String CLIENT_PASSWORD = "123456"; @Test public void testOAuthAccessTokenIsReturned() {

Spring Transactional Annotation

会有一股神秘感。 提交于 2021-02-07 06:13:28
问题 I'm trying to get a better handle on the use of Spring's @Transactional attribute. I understand that it basically wraps the contents of the method marked as @Transactional in a transaction. Would it be appropriate to mark a service/business layer method as transactional, as opposed to the actual DAO method, as I have done here? Service Implementation public class UserServiceImpl implements UserServiceInt{ @Autowired private UserServiceDAO serviceDAO; @Override public User getUser(int id){

How to add basic auth to Autowired testRestTemplate in SpringBootTest; Spring Boot 1.4

纵然是瞬间 提交于 2021-02-07 06:13:24
问题 My OAuth integration test before Spring Boot 1.4 looked as follows(updates just to not use deprecated features): @RunWith(SpringRunner.class) @SpringBootTest(classes = { ApplicationConfiguration.class }, webEnvironment = WebEnvironment.RANDOM_PORT) public class OAuth2IntegrationTest { @Value("${local.server.port}") private int port; private static final String CLIENT_NAME = "client"; private static final String CLIENT_PASSWORD = "123456"; @Test public void testOAuthAccessTokenIsReturned() {

Spring Transactional Annotation

拥有回忆 提交于 2021-02-07 06:07:53
问题 I'm trying to get a better handle on the use of Spring's @Transactional attribute. I understand that it basically wraps the contents of the method marked as @Transactional in a transaction. Would it be appropriate to mark a service/business layer method as transactional, as opposed to the actual DAO method, as I have done here? Service Implementation public class UserServiceImpl implements UserServiceInt{ @Autowired private UserServiceDAO serviceDAO; @Override public User getUser(int id){

Custom Error message with @Preauthorize and @@ControllerAdvice

自古美人都是妖i 提交于 2021-02-07 05:39:05
问题 We are using spring and spring-security-3.2. Recently We are adding annotations @PreAuthorize to RestAPIs(earlier it was URL based). @PreAuthorize("hasPermission('salesorder','ViewSalesOrder')") @RequestMapping(value = "/restapi/salesorders/", method = RequestMethod.GET) public ModelAndView getSalesOrders(){} We already have Global exception handler which annotated with - @ControllerAdvice and custom PermissionEvaluator in place, everything works fine except the error message. Lets say some

How To Implement a progress bar using Spring 3 MVC?

老子叫甜甜 提交于 2021-02-07 05:28:08
问题 Can anyone teach me or direct to a working example to satisfy this requirement. Scenario: List item My Web App is using spring mvc. One of the services it provides is that when the user clicks on a button a long running process will occur on the server. (Query database, write files, write logs, etc...) this process can take a few seconds or a few minutes. *Problem* * * How can I implement the service to update the client of its progress. The service returns true or false if the process was

Spring MVC form:select selected value?

久未见 提交于 2021-02-07 05:10:59
问题 Is there any way to select current value in dropdown list by Spring MVC by <form:options> ? 回答1: Sets 'selected' as appropriate based on bound value. http://static.springsource.org/spring/docs/2.0.x/reference/spring-form.tld.html#spring-form.tld.options 回答2: Here's my fix to this problem. Its massive, but it works genders : qualifier from java model // model.addAttribute("genders", genders); account : binded modelattribute for spring forms fmt:message : translates m to "Mees" (Estonian) <form