spring-mvc

Is there any way to enable or disable the Spring bean definition in applicationContext.xml file?

Deadly 提交于 2020-01-09 10:46:46
问题 Is there any way to enable or disable a java bean definition in application context? <bean id="enBean" classs="com.en.bean.BeanName"> <property name="prop1"/> </bean> Or, is there any way to load the bean conditionally defined in application context? 回答1: There is a new feature @Profile in spring 3.1 that would do the job From here Spring 3.1 introduces the concept of environment profiles. A common use case is the setting up of beans that are different between development, QA and production

Inject HttpServletRequest into Controller

天涯浪子 提交于 2020-01-09 10:06:55
问题 As I know per default are controllers in Spring MVC singletons. HttpServletRequest passed offen to the controller handler method. And its ok, while HttpServletRequest is request-scoped, but I see often HttpServletRequest gets @Autowired into the controller field, like this: @Controller("CMSProductComponentController") @RequestMapping(CMSProductComponentController.CONTROLLER_PATH) public class CMSProductComponentController { @Autowired private HttpServletRequest request; } Could be this a

Inject HttpServletRequest into Controller

青春壹個敷衍的年華 提交于 2020-01-09 10:06:13
问题 As I know per default are controllers in Spring MVC singletons. HttpServletRequest passed offen to the controller handler method. And its ok, while HttpServletRequest is request-scoped, but I see often HttpServletRequest gets @Autowired into the controller field, like this: @Controller("CMSProductComponentController") @RequestMapping(CMSProductComponentController.CONTROLLER_PATH) public class CMSProductComponentController { @Autowired private HttpServletRequest request; } Could be this a

How correctly close the ApplicationContext in Spring?

孤者浪人 提交于 2020-01-09 09:52:20
问题 I am studying for the Spring Core certification and I have some dount about on this question finded into the provided study material: What is the preferred way to close an application context? I know that if I have something like this: ConfigurableApplicationContext context = … // Destroy the application context.close(); by the use of the close() method on the context objet the ApplicationContext is closed and the application is destroyed. But I think that this is not the best way that I have

How correctly close the ApplicationContext in Spring?

巧了我就是萌 提交于 2020-01-09 09:52:09
问题 I am studying for the Spring Core certification and I have some dount about on this question finded into the provided study material: What is the preferred way to close an application context? I know that if I have something like this: ConfigurableApplicationContext context = … // Destroy the application context.close(); by the use of the close() method on the context objet the ApplicationContext is closed and the application is destroyed. But I think that this is not the best way that I have

Does spring mvc have response.write to output to the browser directly?

心不动则不痛 提交于 2020-01-09 09:03:57
问题 I am using spring mvc with freetemplate. In asp.net, you can write straight to the browser using Response.Write("hello, world"); Can you do this in spring mvc? 回答1: You can either: get the HttpServletResponse and print to its Writer or OutputStream (depending on whether you want to send textual or binary data) @RequestMapping(value = "/something") public void helloWorld(HttpServletResponse response) { response.getWriter().println("Hello World") } Use @ResponseBody: @RequestMapping(value = "

Send datas from html to controller in Thymeleaf?

北城余情 提交于 2020-01-09 04:58:11
问题 I must send datas from html page (simple form with few input text fields) to page controller and then to database. I am using thymeleaf 2.0.17, spring 3.0. I searched and checked some solutions but didn't work. Maybe someone had the same problem and find some good solution. Please help. Thanks 回答1: You can find an example in http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#creating-a-form. As the tutorial suggests, you need to use th:object , th:action and th:field to create a

Send datas from html to controller in Thymeleaf?

依然范特西╮ 提交于 2020-01-09 04:58:10
问题 I must send datas from html page (simple form with few input text fields) to page controller and then to database. I am using thymeleaf 2.0.17, spring 3.0. I searched and checked some solutions but didn't work. Maybe someone had the same problem and find some good solution. Please help. Thanks 回答1: You can find an example in http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#creating-a-form. As the tutorial suggests, you need to use th:object , th:action and th:field to create a

Trying to use Spring Boot REST to Read JSON String from POST

半世苍凉 提交于 2020-01-09 04:16:07
问题 Am using the latest version of Spring Boot to read in a sample JSON via Restful Web Service... Here's my pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>myservice</artifactId> <version>0.1.0</version> <parent>

Get Parameter Encoding

馋奶兔 提交于 2020-01-09 03:20:16
问题 I have a problem using spring mvc and special chars in a GET request. Consider the following method: @RequestMapping("/update") public Object testMethod(@RequestParam String name) throws IOException { } to which I send a GET request with name containing an "ä" (german umlaut), for instance. It results in spring receiving "ä" because the browser maps "ä" to %C3%A4 . So, how can I get the correct encoded string my controller? Thanks for your help! 回答1: What about this? Could it help? In your