spring-3

Benefits of JavaConfig over XML configurations in Spring?

筅森魡賤 提交于 2019-11-28 07:11:49
Earlier the configurations used to be in hard coded in the code, later it was externalized to .property files (for sake of avoiding hard coded values, avoiding changing code for the sake of changing configurations..etc) then it moved to XML (for sake of being more standardized, error free..etc) Now, while reading about @Configuration in Spring 3 , looks like we are again moving back to the initial approach. Why would we want to hard-code configurations in the code rather than having it externalized ? There are some advantages Java is type safe. Compiler will report issues if you are

Spring 3 @ImportResource with multiple files

别说谁变了你拦得住时间么 提交于 2019-11-28 06:22:31
I'm trying to find the syntax for importing multiple spring xml context files using Spring 3 @ImportResource annotation. I have tried using comma to separate the filenames as illustrated below but that does not work: @Configuration @ImportResource("spring-context1.xml", "spring-context2.xml") public class ConfigClass { } The doc for @ImportResource says "Indicates one or more resources containing bean definitions to import." so I believe there should be a way to specify multiple context files. Surprisingly, I've not been able to find any example on Google Try: @Configuration @ImportResource( {

Is this a Bug in Spring 3.1.2 ( specifically Spring Portlet MVC's )?

大兔子大兔子 提交于 2019-11-28 06:06:49
问题 Background: I am developing a Portlet using Spring MVC framework deployed in liferay 5.x server. Currently I am using 3.0.0.RELEASE. Everything is working fine as expected. That is, when I use annotations like @RenderMapping(params="myaction=editFolderForm") @RenderMapping(params="myaction=editEntryForm") @RenderMapping @ActionMapping(params="myaction=editEntry") etc. DefaultAnnotationHandlerMapping is working as expected in finding a handler for every request. But, for some valid reason, I

@EnableTransactionManagement annotation with 2 transaction managers

我们两清 提交于 2019-11-28 05:51:45
I am using @Configuration annotation for configuration of spring instead of xml file. I am configuring 2 datasources with different session factory and different transaction managers. I am stuck with a problem here for @EnableTransactionManagement annotation. I read in its documentation that, @EnableTransactionManagement is more flexible; it will fall back to a by-type lookup for any PlatformTransactionManager bean in the container. Thus the name can be "txManager", "transactionManager", or "tm": it simply does not matter. This means whatever name I give to method, it will always search for

How to use property from property file specified in PropertyPlaceholderConfigurer in JSP

无人久伴 提交于 2019-11-27 19:29:35
In my application context I have defined properties file: <context:property-placeholder location="classpath:application.properties" /> I want to get value of the property defined in that file on JSP page. Is there a way to do that in the way ${something.myProperty}? PropertyPlaceholderConfigurer can only parse placeholders in Spring configuration (XML or annotations). Is very common in Spring applications use a Properties bean. You can access it from your view this way (assuming you are using InternalResourceViewResolver ): <bean id="properties" class="org.springframework.beans.factory.config

Encoded slash (%2F) with Spring RequestMapping path param gives HTTP 400

北慕城南 提交于 2019-11-27 19:19:36
This is not a duplicate referenced question , because it is Spring specific. Whoever added that (3 years after the fact!) didn't bother to read the question or comment thread to see what the real answer was. The accepted answer isn't quite the answer, but the author of the answer never came back and edited it like I asked. Given the restful method below, Spring 3.1 gives a 400 error with "The request sent by the client was syntactically incorrect ()." when the token parameter contains a URL encoded slash (%2F), for example " https://somewhere.com/ws/stuff/lookup/resourceId/287559/token/R4o6lI

Multiple scenarios @RequestMapping produces JSON/XML together with Accept or ResponseEntity

跟風遠走 提交于 2019-11-27 19:18:51
I am working with Spring 4.0.7 About Spring MVC, for research purposes, I have the following: @RequestMapping(value="/getjsonperson", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Person getJSONPerson(){ logger.info("getJSONPerson - getjsonperson"); return PersonFactory.createPerson(); } @RequestMapping(value="/getperson.json", method=RequestMethod.GET) public @ResponseBody Person getPersonJSON(){ logger.info("getPerson - getpersonJSON"); return PersonFactory.createPerson(); } Each one works fine, observe both for JSON, with and without extension:

difference between @Component and @Configuration in Spring 3

安稳与你 提交于 2019-11-27 19:09:27
I came across two annotations provided by Spring 3 ( @Component and @Configuration ) I am a bit confused between these. Here is what I read about @Component Put this “context:component” in bean configuration file, it means, enable auto scanning feature in Spring. The base-package is indicate where are your components stored, Spring will scan this folder and find out the bean (annotated with @Component) and register it in Spring container. So I am wondering what is the use of @Configuration then if @Controller will register my beans without the need to declare them in spring configuration xml

org.hibernate.HibernateException: No Session found for current thread

♀尐吖头ヾ 提交于 2019-11-27 18:21:51
I'm getting the above exception with Spring3 and Hibernte4 The following is my bean xml file <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0

Spring: Attaching @Qualifer to Java-configured beans

徘徊边缘 提交于 2019-11-27 17:34:57
问题 In spring, you can XML-configure a bean to have a qualifier. I can't seem to find how I can attach a qualifier if configuring beans through Java annotations. What's up with that? Do I have to use just plain old names? 回答1: If you're using annotations (not Java based configuration), you can use the following to add a qualifier (see the Spring documentation): @Component @Qualifier("myQualifier") public class MyBean { //code } And to wire in the bean, use the following (again, see the Spring