spring-3

Add attributes to the model of all controllers in Spring 3

烈酒焚心 提交于 2019-11-28 18:32:31
Every single view in my Spring 3 app has a set of attributes they can rely on. So the first line of every controller is something like: ControllerHelper.addDefaultModel(model, personManager, request); In there I'll add user object and full name retrieved from the database if person is logged in set of variables which are typically set once (e.g. imagesHost ) set of languages a visitor can switch to current language some statistics (e.g. total # of people in our system) This all allows each view to display the logged in user's name, easily reference an image location, a list of languages and

EJB 3.1 or Spring 3.. When to choose which one?

醉酒当歌 提交于 2019-11-28 16:28:12
问题 EJB achieved many improvements in 3.x versions, Spring is also commonly used and version 3 is a good alternative. There are many articles on web, but no exact comparison about ejb3x versus spring3x.. Do you have any ideas about them, in real world examples which one is better at which conditions? For example, we want to separate db and server, which means our application will be on a server, our database will be in another server.. EJB remoting vs Cluster4Spring etc ? Doing everyting

How to get a method's annotation value from a ProceedingJoinPoint?

核能气质少年 提交于 2019-11-28 16:11:45
I have below annotation. MyAnnotation.java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { } SomeAspect.java public class SomeAspect{ @Around("execution(public * *(..)) && @annotation(com.mycompany.MyAnnotation)") public Object procede(ProceedingJoinPoint call) throws Throwable { //Some logic } } SomeOther.java public class SomeOther{ @MyAnnotation("ABC") public String someMethod(String name){ } } In above class am passing " ABC " with in @MyAnnotation . Now how can i access " ABC " value in procede method of SomeAspect.java class? Thanks! You

When use AbstractAnnotationConfigDispatcherServletInitializer and WebApplicationInitializer?

妖精的绣舞 提交于 2019-11-28 15:10:03
I am working with Spring 4.0.7 I did a research about configure Spring MVC through JavaConfig. Practically until yesterday I have seen two configurations using these two options extends AbstractAnnotationConfigDispatcherServletInitializer extends WebMvcConfigurerAdapter and implements WebApplicationInitializer Note : (2) are two classes, one for extension and the other for implementation I am using (2) because I have found many examples where I am able to configure converters, formatters, resources handlers etc… But in the latest days I have tried to help a question on StackOverflow and I did

Bean's property is not setting from util:list object

元气小坏坏 提交于 2019-11-28 12:16:45
问题 I have declared following list using spring util namespace in my spring configuration file: <util:list id="childList"> <ref bean="child1"/> <ref bean="child2"/> <ref bean="child3"/> </util:list> where all reference bean are marked with @Componant annotation and their respective beans are creating. But whenever I am trying to Autowired any beans property like: @Component public class ListTest{ @Autowired @Qualifier("childList") private List<IParent> list; public List<IParent> getList() {

Spring MVC 3.0: How do I bind to a persistent object

我的梦境 提交于 2019-11-28 10:25:12
I'm working with Spring MVC and I'd like it to bind a a persistent object from the database, but I cannot figure out how I can set my code to make a call to the DB before binding. For example, I'm trying to update a "BenefitType" object to the database, however, I want it to get the object fromthe database, not create a new one so I do not have to update all the fields. @RequestMapping("/save") public String save(@ModelAttribute("item") BenefitType benefitType, BindingResult result) { ...check for errors ...save, etc. } There are several options: In the simpliest case when your object has only

Use custom validation messages in Hibernate + Spring

大城市里の小女人 提交于 2019-11-28 09:24:38
I tried the steps from the answer here: Hibernate Validator, custom ResourceBundleLocator and Spring But still just getting {location.title.notEmpty} as output instead of the message. dispatcher-servlet.xml <bean name="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="validationMessageSource"> <ref bean="resourceBundleLocator"/> </property> </bean> <bean name="resourceBundleLocator" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>/WEB-INF/validationMessages<

Exception in GWT Dev Mode + Spring 3.1 + Hibernate 4.0.1

纵饮孤独 提交于 2019-11-28 08:38:16
I have a GWT+Hibernate+JPA+Spring configuration file which is OK with Spring 3.0.x + Hibernate 3.6.x. When I upgraded to Spring 3.1 and Hibernate 4.0, the following exception is thrown: Is there any known incompatibility withe Hibernate 4 and Spring 3.1? org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/application-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: myPu] Unable to build EntityManagerFactory at org

Spring 3 NamespaceHandler issues with Maven Shade plugin

安稳与你 提交于 2019-11-28 07:24:50
问题 Spring 3.1.1.RELEASE with Apache Maven 3.0.3 and Maven Shade plugin 1.6. Using the mvn shade plugin to package the artifact in an uber-jar, including its dependencies: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.6</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource

How can I authenticate a system user for scheduled processes in Spring?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 07:13:34
问题 we have a Quartz/Spring Batch job, that for audit logging purposes we'd like to have it "authenticated" as a system user. Some of our methods rely on fetching the SecurityContext to do this. The ways of running this job are trusted (or authenticated). We don't want to actually use a password or other token (since the process is basically always spawned by quartz). I tried this private void authenticate() { UserDetails admin = userDetailsService.loadUserByUsername( "admin" ); RunAsUserToken