w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Struts unhandled exception - No result defined for action - Struts Spring & hibernate Integration
This is wrong: String forward = "SUCCESS"; The right String is "success"; String forward = "success"; and, since you are extending ActionSupport, you can use the constant SUCCESS to prevent future syntax errors. String forward = SUCCESS; The same mapping has to exist in Struts.xml. If you put "SUCCESS" in Struts.xml, go and change it, to prevent future headaches... P.S: Same for "ERROR" that should be "error".

Categories : Java

Spring: Injecting Properties using @Value and setting a default
Before all: defaultDbProps location is the same of dbProps one. You are accessing properties value in the wrong way (with spEL); use ${} tag in this manner @Value('${my.property}'), but to have ${} available you need a PropertyPlaceholderConfigurer: <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="propertiesArray"> <list> <ref bean="defaultDbProps"/> <ref bean="dbProps"/> </list> </property> </bean> with this bean defaultDbProps are loaded first, then dbProps overrides properties with the same name

Categories : Spring

struts2-rest plugin..making both struts actions + rest actions work together but. giving java.lang.reflect.InvocationTargetException
ive solved the problem with customMapper.. this is my custom mapper class.... package org.apache.struts2.rest.example; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.dispatcher.mapper.DefaultActionMapper; import com.opensymphony.xwork2.config.ConfigurationManager; public class CustomActionMapper extends DefaultActionMapper { public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) { return getActionMapper(request, configManager).getMapping(request, configManager); } private ActionMapper getActionMapper(HttpServletRequest request, ConfigurationManager configM

Categories : Rest

Eclipse: use Struts Actions of imported Project
You should merge two projects into one, and put struts.xml into src. As far as I remember Eclipse is not able to reference another web project as module, i.e. you have to copy WebContent manually during build, that is why you shouldn't reference other web projects and a main project is not a Java EE project. You should also take into account that Tomcat server is not able to handle Java EE projects if you decide to develop one, for this purpose you should choose full featured Java EE Application server. Even that you have an option to only one web module.

Categories : Java

Spring ApplicationContext Running twice
You've declared the same @Configuration class de.wiegand.mytransport.frontend.config.FrontendConfig in both the ContextLoaderListener and the DispatcherServlet. Both of these create an ApplicationContext. Since the DispatcherServlet context (child) has access to the beans in the ContextLoaderListener context (parent), you'll end up with duplicate beans or even initialization errors (depending on the config). Your FrontendConfig is a WebMvcConfigurerAdapter and should therefore be the context that the DisaptcherServlet loads. If you have no other context (application-wide contxt), remove your ContextLoaderListener declaration in the web.xml.

Categories : Java

Closing a Spring ApplicationContext
You declare ac as ApplicationContext which doesn't define a close() method. Instead of that use any super-type of AnnotationConfigApplicationContext that extends Closeable (e.g. ConfigurableApplicationContext) providing the close() method you need to release all resources.

Categories : Java

Retaining values between multiple JSPs and Actions in Struts 2
In the situation where you want to keep the field values passed from one action to another you could configure the scope of the field. Just place the same field with getters and setters in each action, in your case it will be action1 and action2. The field name is txtid. As well as scope interceptor doesn't include in the defaultStack you should reference it in the action configuration. For example <action name="action1" class="com.package.action.AddId"> <result>/jsp/page2.jsp</result> <interceptor-ref name="basicStack"/> <interceptor-ref name="scope"> <param name="key">mykey</param> <param name="session">txtid</param> <param name="autoCreateSession">true</param> </interceptor-ref&

Categories : Java

How can I pass VM args to applicationContext in spring
In case you trying to access the VM arguments in spring application context, then just add the below bean definition in context file: <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="true"></property> </bean> And access the VM args as ${vm_property}. e.g if you passed the –Dport=5, which can be accessed as <bean class="com.testing.test.MyClass"> <property name="myProperty" value="${port}"></property> </bean>

Categories : Spring

Spring ApplicationContext with AJAX call
Ok, I found the problem. I validated the object (DTO) manually with Hibernate Validator and not with the Spring binding mechanism. The validator object was not "in" Spring because I initializate it via: Validator validator = validatorFactory.getValidator(); Set<ConstraintViolation<MyObjectClass>> constraintViolations = validator.validate(myObject); Now I use the build-in mechanism from Spring (>= version 3.2) public @ResponseBody ArrayNode methodName(@Valid @RequestBody MyObjectClasss myObject, BindingResult result) throws DatatypeConfigurationException { if (result.hasErrors()) { for (ObjectError objectError : result.getAllErrors()) { // work with validation error ... } } }

Categories : Spring

How to write Spring ApplicationContext.xml file?
1) Make sure that you really deploy the spring-beans-3.2.x.RELEASE.jar. It contains a spring.schemas file in its META-INF directory (it must contain the url of the schema location used by you) and a spring-beans-3.2.xsd file in org.springframework.beans.factory.xml directory. 2) The XSD Version is contains only of two parts (major and minor) 3.2 but not 3.2.0! BTW: you can use spring-XXX.xsd without version, then spring use always the newest version (defined in spring.schemas file)

Categories : Java

Failed to load Spring ApplicationContext
When running as junit test using Spring Test annotations, you need to use classpath in the locations like this @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:/context.xml") And I don't use any resources definition in the pom.xml. You can remove that and try like this.

Categories : Spring

Spring MVC and JUnit: Failed to load ApplicationContext
As the stack trace indicates, the Spring runner looks for the XML file in the claspath. So assuming a standard Maven layout, and since this XML file is used by tests, it should be under src/test/resources. It seems like you want to use the same file for your application and your tests. This is a strange choice, since DAO tests shouldn't use the same beans (controllers, etc.) as the real MVC application.

Categories : Java

JUnit Reads applicationContext.xml but claims does not exist
I think this because paths are not read the same way when using JUnit and Servlet container. In fact when using Tomcat, the WEB-INF folder is placed under the root web application folder. And for this, using /WEB-INF/jdbc.properties will work fine. But when using JUnit, this won't be the case, since you will be using your Maven project as directory structure. One solution for this situation, would be to separate properties files used for JUnit tests (even if they are the same as production properties files) and place them under: src/test/resources. Then in your Spring configs, use: <context:property-placeholder location="classpath:jdbc.properties"/> By now, both under Tomcat and JUnit Spring should be able to find your files

Categories : Spring

Failed to load ApplicationContext for JUnit test of Spring controller
As mentioned in duscusion: WEB-INF is not really a part of class path. If you use a common template such as maven, use src/main/resources or src/test/resources to place the app-context.xml into. Then you can use 'classpath:'. Place your config file into src/main/resources/app-context.xml and use code @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:app-context.xml") public class PersonControllerTest { ... } or you can make yout test context with different configuration of beans. Place your config file into src/test/resources/test-app-context.xml and use code @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:test-app-context.xml") public class PersonControllerTest { ... }

Categories : Spring

Spring applicationContext.xml: "The markup in the document following the root element must be well-formed"
The <beans> tag is closed and then more bean definitions are added. Move the closing beans tag so it nests the bean definitions. Another related thing that can burn you with XML config files is using the format tool within your IDE. Never format the XML config with a tool, it can add additional whitespace to your xml which gets interpreted breaking your configuration. In a nutshell your doing this: <beans> <bean id="1"/> </beans> <bean id="2"/> <bean id="3"/> When it should be like: <beans> <bean id="1"/> <bean id="2"/> <bean id="3"/> </beans> Full Configuration With Changes <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://

Categories : Spring

Spring Maven unitTest applicationContext loading wrong file
"classpath:/applicationContext.xml" should look under src/test/resources. But it should be noticed that using that syntax will load the first one it finds and then stop as mentioned by '@chrylis'. I once had similar problem. You must have been using an IDE. There must have been applicationContext.xml file in your target/test-classes/ (in Eclipse IDE) in your project directory that is a copy of your xml file under src/main/webapp/WEB-INF or xml file like it.

Categories : Java

What are the Bean Scope constraits when injecting Managed beans and Properties in to another
Definitely no, you only can access them via FacesContext if your current class is not managed by JSF session. There are. You only can set a managed bean which has a wider scope. That makes sense, cause there's no reason for a bean with @SessionScope, for example, to contain explicit info about a @RequestScoped bean. However, you could access some session info from your request scoped bean if you do it in the other way. Referring to this last question you can get the managed beans from your context in several ways.

Categories : Java

Windsor Castle object factory "GetByName" injecting properties
Once again Typed factory is the solution.

Categories : C#

Spring/REST Application with HOT Deployment: Groovy script does not load dynamically from applicationContext.xml on tomcat startup at runtime
Try creating the controller with Java/Groovy that is compiled and let it get injected the Groovy 'script' as a dependency to do the actual work. I seem to remember doing this before and it might be the annotations or the way Spring loads controllers that makes the 'script' not work for you properly.

Categories : Rest

bean not injecting on spring MVC
You need to add the following to your servlet-context.xml configuration file, you don't need to declare annotated beans in the XML file. <mvc:annotation-driven /> <context:component-scan base-package="com.carloscortina" /> My suggestion would be to download Spring Stool Suite (STS) and create a new spring template project (selecting the MVC template), it will create a runnable project and that way you can see how everything is put together.

Categories : Spring

Struts 2 properties over static fields?
Static final fields are always constant, it's used with the purpose unmodifiable at runtime, resource bundles are reloadable at runtime, and therefore modifiable, so the values of the keys could change depending on which bundle is used to search in. Struts2 uses a hierarchy of such bundles, per action class, package, global resource, etc. Example of such usage is getText() used in localization, it searches the hierarchy of bundles to get a simple value for the given key. The i18n tag even loads the resource bundle dynamically by the user. Other example is a struts configuration struts.properties that could be overridden by the user constants. Without it using a framework would not be possible.

Categories : Java

shortcut for injecting strings with spring
You should not have String beans. Just use their value directly. Create a properties file strings.properties and put it on the classpath strings.key=Region Declare a PropertyPlaceholderConfigurer <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>strings.properties</value> </property> </bean> Then annotate instance field Strings as @Value("${strings.key}") private String key; Spring will inject the value from the strings.properties file into this key String. This obviously assumes that the class in which the @Value annotation appears is a bean managed in the same context as the PropertyPlaceholderConfigurer.

Categories : Java

Injecting a generic IList from spring.net
You have to specify the element-type: <list element-type="Namespace.State, Assembly"> <value>SUSPENDED</value> <value>HALTED</value> </list> where Namespace is the namespace of your class and Assembly the assembly that contains your enum. <list element-type="SandboxConsole.Device.Control.ApplicationEnumerations+State, SandboxConsole"> <value>SUSPENDED</value> <value>HALTED</value> </list> ApplicationEnumerations+State because you try to access an inner class. http://www.springframework.net/doc-latest/reference/html/objects.html#objects-generic-collections-values

Categories : C#

Struts 2 - HTTP Status 404 - No result defined for action
I think you missed to write the method "wateva" in HelloAction. So either write it in place of execute or remove it from your struts mapping. <struts> <!-- Configuration for the default package. --> <package name="default" extends="struts-default"> <action name="hello" class="com.manaar.action.HelloAction"> <result name="success">/hello.jsp</result> </action> </package>

Categories : Java

Struts 2 - Can I access properties of another action which is not on the ValueStack?
Actions are created upon request and don't share the context because it's local to their thread. If you need the property set by the action then you should supply it with parameter in the url or take it from the session. You should create getters and setters for the property you want to pass. Usually passing parameters done with param tag can be used to parametrize other tags. In your case you could use param tag in the result configuration to create a dynamic parameter <result name="searchEmployeesByName" type="redirectAction"> <param name="actionName">department</param> <param name="employeeName">${employeeName}</param> </result> See Dynamic Result configuration.

Categories : Java

Load properties files in session + Struts
Properties props = ... // load your properties file request.getSession().setAttribute("mypropertiesfile", props); But it is not a good practice to use session to store such a things, why you don't simply use cache?

Categories : Java

Spring injecting an interface implementation gives Nullpointer
Seems like you don't have annotations enabled, try adding: <context:annotation-config /> <context:component-scan base-package="<your_package_name>,<your_another_package_name>" /> xmlns: xmlns:context="http://www.springframework.org/schema/context" xsi schema location: http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd

Categories : Java

Rails and user defined actions
The problem here is that you don't retrieve a Booking, you generate an ActiveRecord::Relation : @booking = Booking.where(:friendly_id => params[:friendly_id]) # should be @booking = Booking.where(:friendly_id => params[:friendly_id]).first # or @booking = Booking.find_by(:friendly_id => params[:friendly_id])

Categories : Ruby On Rails

Access Struts 2 action class properties directly
I think you need to have the bean getter method defined properly . Say , if a property is named id and you have a method called getId() in your action. Then it can be accessed directly in the JSP as : OGNL expression: <s:property value="id"/> OR JSTL expression: <c:out value="${action.id}"/>

Categories : Java

Spring injecting or autowiring datasource bean to class
NullPointerException on the line: this.jdbcTemplate.update(sql); If the NPE is actually on that line, then this.jdbcTemplate is obviously null. If this is true then either: The setDataSource(...) method is not being called in Spring, possibly because the @Autowired is not right somehow. It would be easy to add a System.out.println(...) or put a debugging breakpoint in setDataSource to see if it is being called. If it is being called then maybe there are more than one instance of a.b.c.myBeanOne? Are you for sure getting the instance being called from another class from the Spring context? Put a breakpoint in setDataSource and notice the this object reference id. Then put a breakpoint on the this.jdbcTemplate.update(...) line and make sure that the this reference-id is the same.

Categories : Java

Injecting spring bean in Hazelcast entry listener
In Hazelcast you can configure a spring bean as a listener and configure that bean how ever you like. Here is a sample for your case; <hz:listeners> <hz:listener implementation="entryListener"/> </hz:listeners> <bean id="entryListener" class="com.acme.EntryListener"> <property name="customBean" ref="customBean" /> </bean> <bean name="customBean" class="com.acme.CustomBean"/>

Categories : Java

Injecting Custom Principal to Controllers by Spring Security
Fundamentally this seems like trouble integrating with Spring MVC and not a Spring Security issue. Spring Security has no way of knowing that Authentication@getPrinicpal() implements Principal since the API returns an Object. I see a few options for you. Each has some pros and cons, but I think the best is using @ModelAttribute and @ControllerAdvice @ModelAttribute and @ControllerAdvice The easiest option is annotate a method with @ModelAttribute on custom @ControllerAdvice. You can find details in the Spring Reference. @ControllerAdvice public class SecurityControllerAdvice { @ModelAttribute public UserPrincipal customPrincipal(Authentication a) { return (UserPrincipal) a == null ? null : a.getPrincipal(); } } Now in your controller you can do something like thi

Categories : Spring

Injecting queries into DAOs via a spring config file
If the purpose is to facilitate SQL modification without code recompilation, then yes this will do. You just need to inject RuleDao into your DAO classes. However in my opinion SQL query modification should go through standard software lifecycle (design, implement, test, operate). So I'm happy with my SQL queries being hardcoded into DAO classes.

Categories : Java

Powermock and Spring cause ConversionException when injecting EntityManager in test
I had a similar issue and it was suggested to me to create a Resources.java class that Produced an Entity Manager. @Stateful public class Resources implements Serializable { @PersistenceContext (type = PersistenceContextType.TRANSACTION) private EntityManager entityManager; @Produces public EntityManager getEntityManager() { return entityManager; } } I'm still not exactly sure why this solution worked for me... but it did. v/r Ace

Categories : Java

Returning an array of actions defined in controller
You can do ProjectsController.action_methods in your test. Any public method will be returned. Keep in mind do define any non action methods as private If you want to do this for multiple controllers, you can have a look at shared example. eg. shared_examples "test actions" do controller_class.action_methods.each do |action| <your tests> end end and in your test file, simple say it_behaves_like "test actions"

Categories : Ruby On Rails

org.apache.axis2.AxisFault: Axis2 Can't find Spring's ApplicationContext with in .aar file
Try to add this in the spring initialization service in the services.xml: <parameter name="ServiceObjectSupplier" locked="false">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>

Categories : Spring

Injecting custom parameter to request mapping method in Spring MVC
You should be able to retrieve it using the @ModelAttribute tag, and annotating the user as a session attribute, this way: @SessionAttributes("user") public class MyController { @RequestMapping(value = "/{cid}/read") public @ResponseBody boolean markAsRead(@PathVariable("cid") Comment comment, @ModelAttribute("user") User user) { //No need to inject HttpSession and //no need to call user = ((User) session.getAttribute("user")); ... } }

Categories : Spring

Where is all "com.android.camera. - - -" intent filter actions are defined?
instead of hardcoding that String value you should use android.provider.MediaStore.ACTION_IMAGE_CAPTURE, if you mean "similar thing" you can look for other values inside the class MediaStore.

Categories : Java

Struts 2 + Spring and contextConfigLocation
You wouldn't write src/SpringBeans.xml, because your source directory isn't a deployable artifact. You should put the config file either: On the classpath (IMO generally preferable) In WEB-INF (to prevent direct client access) If it's on the classpath, how to get it deployed depends on your build/packaging system. For example, in Eclipse, you can just leave it at the root of src. If you're using Maven, it should go at the root of src/main/resources. If it's not at the root, modify the below accordingly. <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:SpringBeans.xml</param-value> </context-param> Otherwise provide the app-relative path, e.g., <context-param> <param-name>contextConfigLocati

Categories : Spring

Struts spring Hibernate
It is missing a jar file. ServletContextListener is in servlet-api.jar include that jar file in your project. (ServletRequestListener is in the same jar file)

Categories : Hibernate



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.