I think I crashed my setup because my mapping isn't working any more and I don't know why. Here are my web.xml, applicationContext.xml payment-servlet.xml and payment.beans.xml.
**web.xml**
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- Add Support for Spring -->
<!-- Default applicationContext location: /WEB-INF/applicationContext.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- exposes the request to the current thread -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- springapp payment servlet -->
<servlet>
<servlet-name>payment</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath:/spring/servlet/payment-servlet.xml</param-value> -->
<param-value>file:**/webapp/META-INF/spring/servlet/payment-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>payment</servlet-name>
<url-pattern>/payment/*</url-pattern>
<url-pattern>/paymentExternalData</url-pattern>
<url-pattern>/paymentInternalData</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>payment.jsp</welcome-file>
<welcome-file>payment.html</welcome-file>
</welcome-file-list>
</web-app>
**applicationContext.xml**
<context:annotation-config />
<!-- payment servlet
<import resource="classpath:/spring/payment.beans.xml"/> -->
<import resource="file:**/webapp/META-INF/spring/payment.beans.xml"/>
<!-- Auto scan the components -->
<context:component-scan
base-package="com.app.payment.model.PaymentUser" />
**payment-servlet**
<!-- Auto scan the components -->
<context:component-scan base-package="at.dt_i.primesign.payment" />
<!-- Payment controller -->
<bean class="at.dt_i.primesign.payment.controller.PaymentController">
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- PropertyPlaceholderConfigurer
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" depends-on="configuration">
<property name="properties" ref="configuration" />
</bean> -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/configuration.properties</value>
</property>
</bean>
**payment.beans.xml**
<context:annotation-config />
<tx:annotation-driven />
<bean id="paymentDao" class="com.app.payment.model.PaymentDAOImpl" />
<bean id="paymentService" class="com.app.payment.PaymentServiceImpl" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="paymentTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="paymentEntityManagerFactory" />
</bean>
<!-- -->
<bean id="paymentJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="${paymentJpaVendorAdapter.generateDdl}" />
<property name="databasePlatform" value="${paymentJpaVendorAdapter.databasePlatform}" />
</bean>
<bean id="paymentEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="profileDataSource" />
<property name="jpaVendorAdapter" ref="paymentJpaVendorAdapter" />
<property name="persistenceUnitName" value="payment" />
</bean>
My first question: Is my structure right or is there a better solution.
the main goal is to operate with to controller methods /paymentInternalData and /paymentExternalData. But I think the dispatchServlet loads something different because the mapping is not working it only shows the welcome page. but not the 2 sub pages.
I know this is mainly code but I'm not sure what to post, so I posted everything. hopefully anybody can help.
I think your Url-pattern for servlet is correct :
<servlet-mapping>
<servlet-name>payment</servlet-name>
<url-pattern>/payment/*</url-pattern>
<url-pattern>/paymentExternalData</url-pattern>
<url-pattern>/paymentInternalData</url-pattern>
</servlet-mapping>
But the
file:**/webapp/META-INF/spring/servlet/payment-servlet.xml
is not able to load the payment-servlet.xml file.
If your META-INF is under webapp directory then you can do this :
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath:/spring/servlet/payment-servlet.xml</param-value> -->
<param-value>/META-INF/spring/servlet/payment-servlet.xml</param-value>
</init-param>
or
Remove the init-param block and move payment-servlet.xml under webapp/WEB-INF/ directory where web.xml present.
Related
I have a Spring+SpringMVC demo, I can't understand how to use <mvc:annotation-driven/>, when I hava <context:component-scan base-package="com.jiehang.spring.controller" without <mvc:annotation-driven/> in spring-mvc.xml. The project can also run, if so, why do we need to write <mvc:annotation-driven/> in spring-mvc.xml ? Anyone can answer me, please. Thanks
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
spring-mvc.xml:
<context:component-scan base-package="com.jiehang.spring.controller" />
<!-- <mvc:annotation-driven /> -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
spring.xml:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thinXXX" />
<property name="username" value="XXX" />
<property name="password" value="XXX" />
</bean>
<bean id="tsmCountsService" class="com.jiehang.spring.service.impl.TsmCountsServiceImpl">
<property name="tsmCountsDao" ref="tsmCountsDao" />
</bean>
<bean id="tsmCountsDao" class="com.jiehang.spring.dao.impl.TsmCountsDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
Controller:
#Controller
public class FundController {
#Autowired
private TsmCountsService tsmCountsService;
public TsmCountsService getTsmCountsService() {
return tsmCountsService;
}
public void setTsmCountsService(TsmCountsService tsmCountsService) {
this.tsmCountsService = tsmCountsService;
}
#RequestMapping("/queryFund")
public ModelAndView queryFundByFundId() {
List<TsmCounts> funds = tsmCountsService.queryUser();
System.out.println(funds);
return null;
}
}
When I input url: http://localhost:8080/TestSpringmvc/queryFund, I can get output result. So, It doesn't matter if you don't write <mvc:annotation-driven />.
<mvc:annotation-driven /> provides support for annotation-driven MVC controllers (like #RequestMapping and #Controller) although it is the default behaviour, along with this it adds support for validation via #Valid and message body with #RequestBody/ResponseBody.
I am new to Spring-MVC, i am trying to create a Spring-MVC project that uses annotation in controller and also creates databases.
The application works fine, when i write all the xml code in spring-dispatcher-servlet.xml file, but when i separate spring database connection xml and spring servlet xml file, it stops working.
The following code successfully creates tables in database, but it fails to load controllers, it gives me 404 not found page when i try to hit any controller.
If i comment <listner> code in my web.xml file it successfully loads all the controllers, but no database operations performed.
Kindly guide me what i am doing wrong here.
web.xml
<!-- JPA -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring.xml</param-value>
</context-param>
<!-- Servlet Dispatcher -->
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
Spring.xml
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.evantage.models" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/springDB" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<!-- This produces a container-managed EntityManagerFactory; rather than
application-managed EntityManagerFactory as in case of LocalEntityManagerFactoryBean -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="persistenceXmlLocation" value="/WEB-INF/persistence.xml" />
</bean>
<jpa:repositories base-package="com.evantagesoft.springmvctiles.repository"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
Spring-dispatcher-servlet.xml
<context:component-scan base-package="com.evantage.controllers" />
<mvc:annotation-driven />
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
<property name="preparerFactoryClass"
value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" />
</bean>
<!-- View Handler -->
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="favorPathExtension" value="true" />
<property name="mediaTypes">
<map>
<entry key="xml" value="text/xml" />
<entry key="json" value="application/json" />
<entry key="html" value="text/html" />
<entry key="less" value="text/html" />
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="prefix" value="/"/> -->
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</list>
</property>
</bean>
You need to add context:component-scan base-package="controller package" in dispatcher servlet xml to make it work.
Component scan is required to scan the package and register your controller classes
i'm getting this error after i deployed the admin.war file into tomcat manager.I cant startup the site from the manager too..
now i'm seeing this error while trying to startup catalina
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blMergedDataSources' defined in resource loaded from byte array: Cannot resolve reference to bean 'webDS' while setting bean property 'sourceMap' with key [TypedStringValue: value [jdbc/web], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webDS': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:384)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:165)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:445)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:419)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:547)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304)
... 47 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webDS': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 64 more
Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 71 more
Nov 14, 2014 3:13:10 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Nov 14, 2014 3:13:10 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/mycompany] startup failed due to previous errors
here's my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID">
<display-name>mycompany</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>site.root</param-value>
</context-param>
<context-param>
<param-name>patchConfigLocation</param-name>
<param-value>
classpath:/bl-open-admin-contentClient-applicationContext.xml
classpath:/bl-cms-contentClient-applicationContext.xml
classpath:/applicationContext.xml
classpath:/applicationContext-email.xml
/WEB-INF/applicationContext-datasource.xml
/WEB-INF/applicationContext-email.xml
/WEB-INF/applicationContext-security.xml
/WEB-INF/applicationContext-filter.xml
/WEB-INF/applicationContext-workflow.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>shutdownHookMethod</param-name>
<param-value>forceFlush</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- enable configured logging -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.broadleafcommerce.common.web.extensibility.MergeContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- Note: The applicationContext-servlet-cms-contentClient.xml file is used to load static assets
from the Broadleaf CMS such as images. It will match on any URL that contains the static asset
prefix URL in any depth of it. -->
<servlet>
<servlet-name>mycompany</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext-servlet-cms-contentClient.xml
/WEB-INF/applicationContext-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mycompany</servlet-name>
<url-pattern>/mycompany</url-pattern>
</servlet-mapping>
<!-- The RESTApiServlet can be disabled, but doesn't have to be. It will throw an exception if
it is accessed when no endpoints have been registered via Spring. Add /WEB-INF/applicationContext-rest-api.xml
to the merge patchConfigLocation ABOVE applicationContext-security.xml to activate and begin using REST services.
Alternately, this servlet and servlet mapping can be commented out entirely. -->
<servlet>
<servlet-name>RESTApiServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.codehaus.jackson.jaxrs</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RESTApiServlet</servlet-name>
<url-pattern>/api/v1/*</url-pattern>
</servlet-mapping>
<env-entry>
<env-entry-name>mycompany</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>mycompanySite</env-entry-value>
</env-entry>
and the context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<task:annotation-driven />
<bean id="blConfiguration" class="org.broadleafcommerce.common.config.RuntimeEnvironmentPropertiesConfigurer" />
<!-- Set up Broadleaf messaging -->
<bean id="messageSource" class="org.broadleafcommerce.common.util.BroadleafMergeResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:messages</value>
</list>
</property>
</bean>
<!-- Set up custom entity overrides. These are defined in core/src/main/resources -->
<bean id="blMergedEntityContexts" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>classpath:applicationContext-entity.xml</value>
</list>
</property>
</bean>
<!-- Delete this bean to enable caching - leaving it on for development is recommended -->
<!-- as it will allow changes made in the admin or directly on the database to be reflected -->
<!-- immediately. However, caching is obviously beneficial in production. -->
<bean id="blMergedCacheConfigLocations" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>classpath:bl-override-ehcache.xml</value>
</list>
</property>
</bean>
<!-- Delete this section to disable the embedded solr search service. Although this will result in a smaller -->
<!-- application footprint, it will default the search service to use the database implementation, which -->
<!-- is slower and less full-featured. Broadleaf suggests maintaining this solr implementation in the vast -->
<!-- majority of cases. -->
<bean id="solrEmbedded" class="java.lang.String">
<constructor-arg value="solrhome"/>
</bean>
<!--A simple quartz jobs for enabling cart and customer purge functionality. Uncomment the following quartz configurations-->
<!--to activate this functionality (Also, uncomment the 'purgeCartTrigger' and 'purgeCustomerTrigger' configured under SchedulerFactoryBean.-->
<!--Note, you can edit the configuration to customize the functionality. Take a look-->
<!--at PurgeCartVariableNames and PurgeCustomerVariableNames for a list of available params and ResourcePurgeService for additional information. Also,-->
<!--for custom resource retrieval beyond the scope of the existing implementation, ResourcePurgeServiceImpl can be subclassed-->
<!--to provide custom resource retrieval functionality. Please see Quartz documentation for more advanced configuration,-->
<!--such as clustering.-->
<!--<bean id="purgeCartConfig" class="org.springframework.beans.factory.config.MapFactoryBean">-->
<!--<property name="sourceMap">-->
<!--<map>-->
<!--<entry key="SECONDS_OLD" value="2592000"/>-->
<!--<entry key="STATUS" value="IN_PROCESS"/>-->
<!--</map>-->
<!--</property>-->
<!--</bean>-->
<!--<bean id="purgeCartJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">-->
<!--<property name="targetObject" ref="blResourcePurgeService" />-->
<!--<property name="targetMethod" value="purgeCarts" />-->
<!--<property name="arguments">-->
<!--<list>-->
<!--<ref bean="purgeCartConfig"/>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--<bean id="purgeCartTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">-->
<!--<property name="jobDetail" ref="purgeCartJobDetail" />-->
<!--<property name="startDelay" value="30000" />-->
<!--<property name="repeatInterval" value="86400000" />-->
<!--</bean>-->
<!--<bean id="purgeCustomerConfig" class="org.springframework.beans.factory.config.MapFactoryBean">-->
<!--<property name="sourceMap">-->
<!--<map>-->
<!--<entry key="SECONDS_OLD" value="2592000"/>-->
<!--<entry key="IS_REGISTERED" value="false"/>-->
<!--</map>-->
<!--</property>-->
<!--</bean>-->
<!--<bean id="purgeCustomerJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">-->
<!--<property name="targetObject" ref="blResourcePurgeService" />-->
<!--<property name="targetMethod" value="purgeCustomers" />-->
<!--<property name="arguments">-->
<!--<list>-->
<!--<ref bean="purgeCustomerConfig"/>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--<bean id="purgeCustomerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">-->
<!--<property name="jobDetail" ref="purgeCustomerJobDetail" />-->
<!--<property name="startDelay" value="30000" />-->
<!--<property name="repeatInterval" value="86400000" />-->
<!--</bean>-->
<!-- If you want to use a standalone solr server for at least one environment, uncomment the following -->
<!-- three beans and set solr.source.primary, solr.source.reindex, and solr.source.admin in the property file -->
<!-- to be solrServer, solrReindexServer, and solrAdminServer, respectively: -->
<!-- solr.souce.primary=solrServer-->
<!-- solr.souce.reindex=solrReindexServer-->
<!-- solr.souce.admin=solrAdminServer-->
<!-- Then, ensure that the three beans that you just uncommented, below, have their constructor arguments -->
<!-- pointing to the correct URLs of the stand alone server(s) -->
<!-- NOTE this assumes you are using Solr 4.4. -->
<!-- solr.url.admin should point to the ROOT of the server, for example: http://localhost:8983/solr. -->
<!-- solr.url.reindex should point to the reindex core, for example: http://localhost:8983/solr/reindex. -->
<!-- solr.url.primary should point to the primary core, for example, http://localhost:8983/solr/primary. -->
<!-- In version 4.4 and higher of Solr, there is no need to configure the cores or defaultCoreName elements -->
<!-- in solr.xml, as Solr cores are auto discoverable as of 4.4 (see Solr documentation).-->
<!-- So, for Solr 4.4, in stand-alone mode, you should configure the following 3 HttpSolrServer configurations: -->
<!-- <bean id="solrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer"> -->
<!-- <constructor-arg value="${solr.url.primary}"/> -->
<!-- </bean> -->
<!-- <bean id="solrReindexServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer"> -->
<!-- <constructor-arg value="${solr.url.reindex}"/> -->
<!-- </bean> -->
<!-- <bean id="solrAdminServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer"> -->
<!-- <constructor-arg value="${solr.url.admin}"/> -->
<!-- </bean> -->
<bean id="blSearchService" class="org.broadleafcommerce.core.search.service.solr.SolrSearchServiceImpl">
<constructor-arg name="solrServer" ref="${solr.source.primary}" />
<constructor-arg name="reindexServer" ref="${solr.source.reindex}" />
<constructor-arg name="adminServer" ref="${solr.source.admin}" />
</bean>
<bean id="rebuildIndexJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="blSearchService" />
<property name="targetMethod" value="rebuildIndex" />
</bean>
<bean id="rebuildIndexTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="rebuildIndexJobDetail" />
<property name="startDelay" value="${solr.index.start.delay}" />
<property name="repeatInterval" value="${solr.index.repeat.interval}" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="rebuildIndexTrigger" />
<!--<ref bean="purgeCartTrigger" />-->
<!--<ref bean="purgeCustomerTrigger" />-->
</list>
</property>
</bean>
<!-- Broaldeaf Commerce comes with an Image Server that allows you to manipulate images. For example, the
demo includes a high resolution image for each product that is reduced in size for browsing operations -->
<bean id="blStaticMapNamedOperationComponent" class="org.broadleafcommerce.cms.file.service.operation.StaticMapNamedOperationComponent">
<property name="namedOperations">
<map>
<entry key="browse">
<map>
<entry key="resize-width-amount" value="400"/>
<entry key="resize-height-amount" value="400"/>
<entry key="resize-high-quality" value="false"/>
<entry key="resize-maintain-aspect-ratio" value="true"/>
<entry key="resize-reduce-only" value="true"/>
</map>
</entry>
<entry key="thumbnail">
<map>
<entry key="resize-width-amount" value="60"/>
<entry key="resize-height-amount" value="60"/>
<entry key="resize-high-quality" value="false"/>
<entry key="resize-maintain-aspect-ratio" value="true"/>
<entry key="resize-reduce-only" value="true"/>
</map>
</entry>
</map>
</property>
</bean>
<!-- This is an example of a custom dialect definition that uses a custom processor -->
<!-- The second bean registers the dialct to the blWebTemplateEngine -->
<!-- Note that the same thing could be done for the blEmailTemplateEngine -->
<!--
<bean id="myDialect" class="com.mycompany.common.web.dialect.MyDialect">
<property name="processors">
<set>
<bean class="com.mycompany.common.web.processor.MyProcessor" />
</set>
</property>
</bean>
<bean id="blWebTemplateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="dialects">
<set>
<ref bean="myDialect" />
</set>
</property>
</bean>
-->
<!-- The following two beans are defined like this in Broadleaf Commerce. However, -->
<!-- you may want to override the bean definitions by uncommenting these two beans -->
<!-- to control whether or not templates are cacheable. This will generally be desireable -->
<!-- in production environments, but likely not in development environments. -->
<!--
<bean id="blWebTemplateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="${cache.page.templates}"/>
<property name="cacheTTLMs" value="${cache.page.templates.ttl}" />
<property name="characterEncoding" value="UTF-8" />
</bean>
<bean id="blEmailTemplateResolver" class="org.thymeleaf.templateresolver.ClassLoaderTemplateResolver">
<property name="prefix" value="emailTemplates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="${cache.page.templates}"/>
<property name="cacheTTLMs" value="${cache.page.templates.ttl}" />
<property name="characterEncoding" value="UTF-8" />
</bean>
-->
<bean id="jsLocations" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>/js/</value>
</list>
</property>
</bean>
<bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
<property name="collectionRef" value="jsLocations" />
<property name="targetRef" value="blJsLocations" />
</bean>
<bean id="cssLocations" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>/css/</value>
</list>
</property>
</bean>
<bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
<property name="collectionRef" value="cssLocations" />
<property name="targetRef" value="blCssLocations" />
</bean>
<bean id="blJsResources" class="org.broadleafcommerce.common.web.resource.BroadleafResourceHttpRequestHandler">
<property name="locations" ref="blJsLocations"/>
<property name="handlers" ref="blJsHandlers" />
</bean>
<bean id="blCssResources" class="org.broadleafcommerce.common.web.resource.BroadleafResourceHttpRequestHandler">
<property name="locations" ref="blCssLocations"/>
<property name="handlers" ref="blCssHandlers" />
</bean>
Thanks#MateiFlorescu:hey..i changed my mysql default port number and config. it was running on port 8080 which is the default port of apache tomcat.so i changed mysql port number to 3306.Now the program run smoothly!!
You need a reference to the datasource in web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/dbname</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Also, what app server are you using? Tomcat (like in the questions tags) or Jetty (like you are mentioning in your comments)?
exception:
g.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'utenteDAO': Injection of autowired dependencies
failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private org.hibernate.SessionFactory
com.mauro.soclib.dao.UtenteDAO.sessionFactory; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
matching bean of type [org.hibernate.SessionFactory] found for
dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
spring-security.xml
<beans...">
<context:annotation-config />
<context:component-scan base-package="com.mauro" />
<http auto-config='true' >
<intercept-url pattern="/admin**" access="ROLE_USER" />
<intercept-url pattern="/paginaConGrafica**" access="ROLE_USER" />
<form-login login-page="/login"
default-target-url="/paginaConGrafica"
authentication-failure-url="/error-login.html"
login-processing-url="/j_spring_security_check"/>
<logout logout-success-url="/index" />
</http>
<beans:bean id="restAuthenticationProvider"
class="com.mauro.soclib.security.customAuthenticationProvider" autowire="byType">
</beans:bean>
<authentication-manager alias="authenticationManager">
<authentication-provider
ref="restAuthenticationProvider" />
</authentication-manager>
</beans:beans>
servlet
<?xml version="1.0" encoding="UTF-8"?>
<context:annotation-config />
<context:component-scan base-package="com.mauro.soclib" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/social_libreria" />
<property name="username" value="root" />
<property name="password" value="1234" />
</bean>
<bean id="UtenteValidator" class="com.mauro.soclib.validator.UtenteFormValidator" />
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:message" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- Scan for the domain objects with the ORM annotation -->
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="packagesToScan" value="com.mauro.soclib" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="10000000" />
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
web.xml:
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- link al config file security -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- specifiche della servlet -->
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
Add this entries to your dispatcher servlet,
<bean id="utenteDAO" class="path" />
<bean id="utenteDAOImplementation class" class="path" />
it is throwing error because you have not autowired the dependencies
EDIT:
try defining the session factory,
#Autowired
#Qualifier("sessionFactory")
public void seSessionFactory(SessionFactory sessionFactory) {
this.setSessionFactory(sessionFactory);
}
change the location of the project folder and set system path and path properties accordingly .It works in our case.But we are unable to find the exact reason.
I am trying to configure internazionalization in Spring MVC (using changing of locales via links), however, it doesn't seem to be working at all: default locale is always ru for some reason, though default is set to en, they are not changing using links, spring messages are displayed empty regardless of the chosen locale (messages_de, messages_en and messages_ru.properties DO exist at classpath (src/main/resources)). They contain e.g.
label.test=Russian
and i refer to them as
<spring:message code="label.test" />
in my JSPs. They are not being displayed like that.
I take it as even messageSource is not found, even though there are no errors or warnings. I'd really appreciate any help as I'm trying to figure it out for really long time. Apparently, I've missed some details, but I definitely can't catch the problem. Here are my configuration files (or most relevant parts).
root-context.xml
<context:component-scan base-package="... .dao" />
<context:component-scan base-package="... .service" />
<import resource="data.xml" />
<import resource="security.xml" />
mvc-dispatcher-servlet.xml
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="sitelocale" />
</bean>
</mvc:interceptors>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
data.xml
<!-- Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<!-- //////////////////////////////////////////////////////////////////////////
" -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.databaseurl}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- ////////////////////////////////////////////////////////////////////////// -->
<!-- Hibernate SessionFactory configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.tsystems.javaschool.kts.domain" />
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
</props>
</property>
</bean>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
You don't need to prefix the basename value with "classpath:", try to change it as follows:
<property name="basename" value="messages" />
Adding the following should allow you to change the lang with a URL parameter named "lang" (i.e. lang=en). This will allow you to override browser default settings and explicitly declare the language in use.
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
Also, ensure in the deployed webapp that the message files are located under WEB-INF/classes/ if you are going to use classpath:messages as a basename.
Also check if you add this at the top
<%# page contentType="text/html;charset=UTF-8" %>