Application not working after modify dispatcher-servlet.xml in spring mvc - spring-mvc

I'm new to the spring framework. Currently I studying about spring framework. I follow this tutorials,
http://netbeans.org/kb/docs/web/quickstart-webapps-spring.html
http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html
But I have a problem in both example, after adding beans to dispather-servlet.xml and modify application-contex.xml application is not deploy. It gives following massage.
In-place deployment at C:\Users...\Documents\NetBeansProjects\springapp\build\web
Initializing...
deploy?DEFAULT=C:\Users...\Documents\NetBeansProjects\springapp\build\web&name=springapp&contextroot=/springapp&force=true failed on GlassFish Server 3.1.2
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.ClassNotFoundException: springapp.web.HelloController. Please see server.log for more details.
C:\Users...\Documents\NetBeansProjects\springapp\nbproject\build-impl.xml:728: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 2 seconds)
Please help to solve this.
Thank you in advance.
PS:-
#shazinltc -
Here is my dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<bean name="helloService" class="service.HelloService" />

I manage to solve my problem with following tutorial.
https://sites.google.com/site/springmvcnetbeans/step-by-step/
This tutorial is quite simple and more specific and descriptive in each step. I recommend this tutorial for beginners in spring.

Related

Will my application work if i don't give handlerMapping in configuration file?

This is my spring-servlet.xml file. I am new to spring MVC. Do we need to define bean for HelloWorld.Controller. If i don't define will it work?
<bean id="viewResolver" class=" org.springframework.web.servlet.view. InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean name="/welcome.htm" class="com.vaannila.HelloWorldController" >
<property name="message" value="Hello World!" />
</bean>
</beans>
If i don't give this bean definition
<bean name="/welcome.htm" class="com.vaannila.HelloWorldController" >
<property name="message" value="Hello World!" />
</bean>
MyApplication should work or not? I am new to spring MVC. In few tutorial this code is there and in few its not there. Please explain.
Yes, you will need to define the bean (way to create instance of class) for all the Controller/Service/Dao/Components class you want to use and set relevant properties.
I would recommend you to use Annotation based configuration (spring boot) as it eases all this process. You can find lot of tutorials on getting stated with spring boot. Here is one such good tutorial https://www.mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/

Upgrade of Spring webflow 1.0 to 2.4.2 - Setting default flow id?

I'm very much new to spring webflow framework and I have been working on upgrading the existing project on spring webflow 1.0 to use spring webflow 2.4.2 latest framework. Currently on our project we are using the defaultFlowId in dispatcher-servlet.xml and there is a corresponding setter method at FlowController.java of spring webflow 1.0 but it is not available with the current webflow framework.
I would like to understand if there is any alternative for the same ?
(dispatcher-servlet.xml)
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/**/index.htm=loginController
</value>
</property>
</bean>
<bean name="loginController" class="com.example.ui.controllers.LoginController">
<property name="defaultFlowId" value="init-flow" />
<property name="flowExecutor" ref="flowExecutor" />
</bean>
Now it says, Caused By: org.springframework.beans.NotWritablePropertyException: Invalid property 'defaultFlowId' of bean class [com.example.ui.controllers.LoginController]: Bean property 'defaultFlowId' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Since there is no setDefaultFlowId() in latest FlowController.java of org.springframework.webflow.mvc.servlet.FlowController
Anyone who worked/used the above method ? or can i know whether we can define the same kind of defaultId in other ways ?
Any help would be greatly appreciated !
We have upgraded. Here is the flow definition that we are required to use in order that the flow is maintained and default flow is used:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/**/index.htm=yourController
</value>
</property>
</bean>
And the rest:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location id="index" path="/WEB-INF/initialflow.xml" />
</webflow:flow-registry>

Migration from Glassfish 3.1 to Glassfish 4.0

There seems to be a problem with migrating from Glassfish 3.1 to Glassfish 4.x.
I am currently encountered with the following errors:
StandardWrapperValve[DispatcherServlet]: Servlet.service() for servlet DispatcherServlet threw exception java.lang.NullPointerException at com.sun.faces.facelets.tag.TagAttributeImpl.getInt(TagAttributeImpl.java:175) at com.sun.faces.facelets.tag.jstl.core.ForEachHandler.getEnd(ForEachHandler.java:266) at ......................
The code responsible for this works perfectly fine in Glassfish 3.1 but now fails in 4.x.
I've tried this answer out but no luck : How to set -Dorg.apache.el.parser.COERCE_TO_ZERO=false programmatically
Anyone who has encountered this issue?
Here is part of my applicationContext.xml stating the solution on the tutorial:
<bean id="trustStore" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" value="#{#systemProperties}" />
<property name="targetMethod" value="putAll" />
<property name="arguments">
<props>
<prop key="org.apache.el.parser.COERCE_TO_ZERO">false</prop>
</props>
</property>
</bean>
Thank you.

using c3p0 with java MVC (JDK 1.6)

I'm trying to create global connections for multiple WAR files (apps) to use.
Each project use entity manager architecture and maven. I'm using spring 3.5.1, tomcat 6.0.39, JDK 1.6.0_45, C3P0 0.9.1.2, hibernate-c3p0 4.2.3.Final, com.mchange c3p0 0.9.2
I saw examples all over but none works for me, I'm not sure why.
I tried almost everything, but I have no clue what's wrong.
I've written into server.xml the following:
<Resource auth="Container"
description="DB Connection"
driverClass="com.mysql.jdbc.Driver"
maxPoolSize="20"
minPoolSize="12"
acquireIncrement="1"
name="jdbc/testdb1"
user="root"
password=""
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/test_db1?autoReconnect=true" />
and into context.xml the following:
<ResourceLink name="jdbc/testdb1"
global="jdbc/testdb1"
type="javax.sql.DataSource" />
and into web.xml the following:
<resource-ref>
<res-ref-name>jdbc/testdb1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
and my project (app) specific configuration:
PART 1 (JPA XML FILE):
<bean id="transactionManagerMysql" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emfMysql"/>
</bean>
<bean id="emfMysql" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="jdbc/testdb1" />
<property name="persistenceXmlLocation" value="classpath:persistence-infrastructure.xml" />
<property name="persistenceUnitName" value="puMysql" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<jpa:repositories base-package="domain.data.repository"
entity-manager-factory-ref="emfMysql"
transaction-manager-ref="transactionManagerMysql"/>
PART 2 (PERSISTENCE XML FILE):
<persistence-unit name="puMysql" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>domain.Mysqltable1</class>
<properties>
<property name="hibernate.connection.datasource" value="jdbc/testdb1"/>
</properties>
</persistence-unit>
I get an exception:
Error creating bean with name 'emfMysql' defined in class path resource [datasource-tx-jpa-infrastructure.xml]: Cannot resolve reference to bean 'jdbc/testdb1' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jdbc/testdb1' is defined
I hope someone can help me :)
Thanks ahead
It said that the datasource resource you defined in tomcat server.xml is not a bean in spring. You should define a datasource bean like this:
<bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/DatabaseName"/>
</bean>
And use this bean instead of jndi name for datasource property of emfMysql.
Please refer this answer

Flex + Spring + BlazeDS + Glassfish + OpenMQ - How do you configure the web-application-config for OpenMQ?

I have the spring-flex-testdrive example (JMS chat application which uses a Topic to pub/sub messages) to work on Tomcat with ActiveMQ now I want to run this example on Glassfish with OpenMQ.
This is a related sample config I found online but it doesn't quite work for the Flex/Glassfish/OpenMQ/BlazeDs/Spring-Integration technology combination.
(Link)
I can deploy it on Glassfish but it can't connect to the destination. I've seen forums mention just replace ActiveMQ with OpenMQ classes/bean declarations but that does not appear to be the case. How do you configure the web-application-context.xml for OpenMQ? What are the common gotcha's?
Thanks.
<bean id="connectionFactory" class="CustomOpenMqConnectionFactoryBean">
<property name="imqAddressList" value="localhost:7676" />
<property name="imqDefaultUsername" value="admin" />
<property name="imqDefaultPassword" value="admin" />
</bean>
<bean id="chatTopic" class="com.sun.messaging.Topic">
<constructor-arg type="java.lang.String" value="cTopic"/>
</bean>

Resources