<beans xmlns:util="http://www.springframework.org/schema/util">
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="misfireInstruction">
<util:constant static-field="org.quartz.CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW"/>
</property>
</bean>
</beans>
I'm receiving org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'util:constant'.
You have defined xml namespace, but not schema location. You should add:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
(for Sprint 3, for Spring 2.5 it would be spring-util-2.5.xsd etc.).
Solved it using
<bean id="myField"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField" value="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
</bean>
Related
I'm working on a maven project using Spring framework.
Instead of writing raw text in JSPs I prefer to use <spring:message .../> tag and register my messages in a .properties file.
I get this warning when requesting a page :
ResourceBundle [messages] not found for MessageSource: Can't
find bundle for base name messages, locale fr
Which then brings an exception about the message not being found (obviously).
Here's my project's hierarchy :
my project's hierarchy
Here's my springapp-servlet.xml :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="app.core" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/">
</property>
<property name="suffix" value=".jsp">
</property>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="fr" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>
<mvc:resources mapping="/public/**" location="/WEB-INF/resources/"
cache-period="31556926"/>
<mvc:annotation-driven />
</beans>
From the documentation:
The basenames follow ResourceBundle conventions: essentially, a fully-qualified classpath location. If it doesn't contain a package qualifier (such as org.mypackage), it will be resolved from the classpath root.
(emphasis mine)
So it should be under src/main/resources.
I want to build a login with spring social, and I have implemented a *xml whit the next configuration, but the url http://www.springframework.org/schema/social/facebook is wrong?
<?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:facebook="http://www.springframework.org/schema/social/facebook"
xmlns:twitter="http://www.springframework.org/schema/social/twitter"
xmlns:social="http://www.springframework.org/schema/social"
xmlns:linkedin="http://www.springframework.org/schema/social/linkedin"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/social/facebook http://www.springframework.org/schema/social/spring-social-facebook.xsd
http://www.springframework.org/schema/social/linkedin http://www.springframework.org/schema/social/spring-social-linkedin.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/social/twitter http://www.springframework.org/schema/social/spring-social-twitter.xsd
http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:/itrippingWeb/src/main/resources/application.properties" />
<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}" app-namespace="socialshowcase" />
<social:jdbc-connection-repository/>
<bean id="userIdSource" class="org.springframework.social.security.AuthenticationNameUserIdSource" />
<bean id="connectController" class="org.springframework.social.connect.web.ConnectController" autowire="constructor">
<property name="connectInterceptors">
<list>
<bean class="org.springframework.social.showcase.facebook.PostToWallAfterConnectInterceptor" />
<bean class="org.springframework.social.showcase.twitter.TweetAfterConnectInterceptor" />
</list>
</property>
</bean>
<bean id="psc" class="org.springframework.social.connect.web.ProviderSignInController" autowire="constructor" />
<bean id="signInAdapter" class="org.springframework.social.showcase.signin.SimpleSignInAdapter" autowire="constructor" />
<bean id="disconnectController" class="org.springframework.social.facebook.web.DisconnectController"
c:_0-ref="usersConnectionRepository" c:_1="${facebook.clientSecret}" />
</beans>
And this xml retrieve me the next exception:
Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element
'facebook:config'.
- schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/social/spring-
social-facebook.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element
of the document is not <xsd:schema>.
Anybody knows the problem?
thank you!!!!
I think this has to do with your pom missing some of the dependencies.
Is spring-social-security in your dependency?
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.1.0.RELEASE</version>
Here is a similar application with the same config as your spring xml above. Here is the pom it uses https://github.com/spring-projects/spring-social-samples/blob/master/attic/spring-social-showcase-xml/pom.xml
Here is a reference to a similar error resolved by fixing the pom dependency https://github.com/spring-projects/spring-social-facebook/issues/79
Actually the url "http://www.springframework.org/schema/social/facebook" links to nowhere.
I found another schema files location: http://docs.spring.io/autorepo/schema/
I used "http://docs.spring.io/autorepo/schema/spring-social/current/social/spring-social.xsd" and it works for me.
I'm working on a spring and JPA project. I had configured my JPA Persistence Unit in the Persistence.xml and here's my spring configuration file.
My application works fine, but I didn't understand how does spring framework detects the Persistence Unit defined in my Persistence.xml file and injects it without being defined in my spring bean configuration file .
Can anybody answer me please ?
<?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:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="ma.professionalpartners.fireAppBusiness.dao"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="fireApp-Domain" />
</bean>
<bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="jpaTransactionManager" />
</beans>
You have provided the name for the persistence unit, when configuring the entityManagerFactory bean:
<property name="persistenceUnitName" value="fireApp-Domain" />
The persistence.xml file MUST be on certain paths, so that Spring simply searched in those locations. After finding the file, it parses the XML content, and if there is a single PersistenceUnit, that is made the default one. Of course, if you specify a name (as you did), then it looks exactly for that PersistenceUnit.
I am creating a sample web application with spring 3.0 and mongoDB. Following is my root-context.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<import resource="classpath:mongo-config.xml"/>
</beans>
and my mongo-config.xml file is
<?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:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<!-- Default bean name is 'mongo'. write concern set to SAFE to ensure unique indexes -->
<mongo:mongo host="localhost" port="27017" write-concern="SAFE"/>
<mongo:repositories base-package="com.dashboard.repositories" />
<bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
<constructor-arg name="mongo" ref="mongo"/>
<constructor-arg name="databaseName" value="DASHBOARD"/>
<constructor-arg name="credentials" ref="userCredentials"/>
</bean>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
<property name="writeResultChecking">
<util:constant static-field="org.springframework.data.mongodb.core.WriteResultChecking.EXCEPTION" ></util:constant>
</property>
</bean>
<bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials">
<constructor-arg name="username" value="test"/>
<constructor-arg name="password" value="abc123"/>
</bean>
</beans>
when i start the tomcat server, there is no database "Dashboard" created. What is wrong with this code, Kindly help me. Thanks in advance.
For making it visible to other viewers i will put my comment into the answer. In Mongo schemas are dynamic and heterogenous so mongo cannot create a fixed schema as RDMS before inserting any data. Here is a more detailed explanation.
I'm facing a very weird issue. I'm tring to configure the properties of my datasource declared in my spring applicationcontext.xml file via a PropertyPlaceholderConfigurer class. The application context file looks like this:-
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.4.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Spring configurations used by LCM Impl classes -->
<bean id="lcmPropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/activemq.properties</value>
<value>classpath:/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy- method="close">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
I have tried using the context:property-placeholder tag as well but it doesn't seem to have any effect. The above mentioned properties files are deployed successfully under the WEB-INF/classes directory as well.
For some reason, the spring container is able to load the properties files(checked with an invalide properties file and it throws a FNF exception) but not able to substitute the property placeholders with their values.
I'm using a tomcat 7 WS with the CATALINA.BASE pointing to my runtime. Has anybody faced this issue before? Any solutions?
Take that leading slash out of the values:
<value>classpath:activemq.properties</value>
<value>classpath:jdbc.properties</value>
Try the following configuration.
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:activemq.properties</value>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
The issue is likely the fact that you even named the PropertyPlaceholderConfigurer bean. Most Spring internal beans are not given an id, as the framework is configured to look for certain bean names, and often the default bean name is the auto-generated name based on the object type.