I am giving below snippet in spring security.xml
<!-- Exception Mapping configuration -->
<bean id="securityExceptionTranslationHandler"
class="com.abc.xyz.ExceptionMappingFailureHandler" >
<property name="exceptionMappings">
<props>
<prop key="org.springframework.security.authentication.CredentialsExpiredException">/408</prop>
</props>
</property>
</bean>
I am getting error while starting tomcat itself saying :
Invalid property exceptionMappings of com.abc.xyz.ExceptionMappingFailureHandler class :Bean Property exceptionMappings is not writtable or has an invalid setter method .
What should be content of com.abc.xyz.ExceptionMappingFailureHandler class ?
Any Help would be appreciated !
Your class should look something like this to work:
package com.abc.xyz;
public class ExceptionMappingFailureHandler {
public void setExceptionMappings(Map mappings) {
...
}
}
The important thing is that there is a setter with that name, it returns void, and accepts a single argument of type Map.
Related
In my project I'm using Spring 3 with Neo4j 2.0.1, I was using the embedded mode and everything was working fine.
In my code I use the Neo4jTemplate (#Autowired in my services) as well as the GraphRepository and RelationshipOperationsRepository.
I wanted to migrate my coode to use the standalone mode. Here's what I did :
In spring-context.xml, I made it like this :
<!-- Neo4J -->
<!-- neo4j:config storeDirectory="${neo.storeDir}" base-package="net.nextep.nextenergy.domain.graph" /-->
<bean id="graphDatabase" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data/" index="0"/>
</bean>
<neo4j:repositories base-package="net.nextep.nextenergy.repository.graph" />
I tried to run it, I got this error :
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'neo4jTemplate' is defined
I tried then to remove the #Autowired Neo4jTemplate from my services, use #Autowired private SpringRestGraphDatabase graphDB and create a new Template this way private Neo4jTemplate template = new Neo4jTemplate((GraphDatabase) graphDB)
And I still get the same error :
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userNodeRepository': Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'neo4jTemplate' is defined
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'neo4jTemplate' is defined
...
The UserNodeRepository :
#Repository
public interface UserNodeRepository extends GraphRepository<UserNode>,
RelationshipOperationsRepository<UserNode>{
public UserNode findById(String id);
public Node findNodeById(String id);
#Query("match (u:UserNode)-[:HABILITATED]->(f:Folder) where ID(u) = {0} return f")
public Set<Folder> getAllowedFoldersFirstLevel(UserNode user);
}
Am I doing wrong?
Name your bean "graphDatabaseService" and pass it to the config which you didn't create:
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="net.nextep.nextenergy.domain.graph" />
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data/" index="0"/>
</bean>
<neo4j:repositories base-package="net.nextep.nextenergy.repository.graph" />
How can one set the connection pool size for a DBCP datasource? Also, is the default datasource pooled?
I tried to set maxTotal (http://commons.apache.org/proper/commons-dbcp/configuration.html), but it returns an invalid property error.
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="poolPreparedStatements" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="true"/>
<property name="validationQuery" value="SELECT 1 FROM DUAL"/>
<property name="timeBetweenEvictionRunsMillis" value="30000"/>
<property name="maxTotal" value="1"/>
</bean>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class pat
h resource [META-INF/spring/base-gateway.xml]: Error setting property values; nested exception is org.springframework.be
ans.NotWritablePropertyException: Invalid property 'maxTotal' of bean class [org.apache.commons.dbcp.BasicDataSource]: B
ean property 'maxTotal' is not writable or has an invalid setter method. Does the parameter type of the setter match the
return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCap
ableBeanFactory.java:1361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBea
nFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBea
nFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanF
actory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.jav
a:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFac
tory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationCo
ntext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at sf.av.core.gateway.GenericGateway.main(GenericGateway.java:23)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxTotal' of bean class [org.apache
.commons.dbcp.BasicDataSource]: Bean property 'maxTotal' is not writable or has an invalid setter method. Does the param
eter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1024)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:900)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCap
ableBeanFactory.java:1358)
... 13 more
You most likely have a mismatch between the version of the DBCP jar you are using and the configuration documentation, for example:
Users should also be aware that some configuration options (e.g. maxActive to maxTotal) have been renamed to align them with the new names used by Commons Pool 2.
Does the BasicDataSource class from the jar you are using have the maxTotal setter on it or not?
I have the following Java class defined in src/java
package org.davisworld.trip;
public class AirportHbm {
private long id;
private String name;
private String iata;
private String state;
private String lat;
private String lng;
// getters/setters defined
}
I have the hbm.cfg.xml file defined as follows in conf/hibernate:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping resource="AirportHbm.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I have the AirportHbm.hbm.xml file configured as follows in conf/hibernate:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.davisworld.trip.AirportHbm" table="usgs_airports">
<id name="id" column="airport_id">
<generator class="native"/>
</id>
<property name="name" type="java.lang.String">
<column name="airport_name" not-null="true" />
</property>
<property name="iata" type="java.lang.String">
<column name="locid" not-null="true" />
</property>
<property name="state" />
<property name="lat" column="latitude" />
<property name="lng" column="longitude" />
</class>
</hibernate-mapping>
And lastly, I have an AirportHbmConstraints.groovy file in the src/java folder:
package org.davisworld.trip
class AirportHbmConstraints {
static constraints = {
name()
iata(maxSize:3)
state(maxSize:2)
lat()
lng()
}
}
When I try to run the app, I get this error when Spring is initializing the web app context:
Caused by: java.lang.ClassCastException: org.davisworld.trip.AirportHbmConstraints cannot be cast to groovy.lang.Script
The tutorial I was following originally said that the AirportHbmConstraints.groovy file shouldn't have a class; it should just be a script:
package org.davisworld.trip
static constraints = {
name()
iata(maxSize:3)
state(maxSize:2)
lat()
lng()
}
But when I do that, STS gives me a compiler error:
Groovy:Modifier 'static' not allowed here.
Anyone know what I'm doing wrong? What is the correct way to apply constraints in Groovy to a Java domain class?
Many thanks,
Vito
When using constraints scripts with a Hibernate domain you do not use a class declaration or the static modifier as explained in section 15.3 Adding Constraints of the Grails documentation.
The correct constraint script would be:
constraints = {
iata maxSize: 3
state maxSize: 2
}
Note that fields without a constraint and the parentheses on the field declaration are optional.
I'm using password-parameter (as below) to customize the name of the request parameter which contains the password. How to do the same with remember-me (default _spring_security_remember_me) ?
<security:form-login password-parameter="j_password_input" ... />
You have a few options which I have explained in further detail below
Use the Security Namespace with a BeanPostProcessor
Use the services-ref and configure RememberMeServices Manually
Use the Security Namespace with a BeanPostProcessor
The namespace does not have support for configuring the remember me parameter, but you can use a tip from the FAQ on how to still use the namespace support, but customise the result. The trick is to use a BeanPostProcessor to set the parameter field on AbstractRememberMeServices. You can find an example of this below:
public class MyBeanPostProcessor implements BeanPostProcessor {
public Object postProcessAfterInitialization(Object bean, String name) {
if (bean instanceof AbstractRememberMeServices) {
AbstractRememberMeServices rememberMe = (AbstractRememberMeServices) bean;
rememberMe.setParameter("myParamname");
}
return bean;
}
public Object postProcessBeforeInitialization(Object bean, String name) {
return bean;
}
}
Then you would need to use the namespace as you normally would and add MyBeanPostProcessor to your Spring configuration as shown below:
<security:http ..>
...
<security:remember-me/>
</security:http>
<bean class="sample.MyBeanPostProcessor"/>
Use the services-ref and configure RememberMeServices Manually
You can also use the services-ref attribute too, but this involves a little more configuration. For example, if you wanted you could use the following configuration:
<security:http ..>
...
<security:remember-me services-ref="rememberMeServices"/>
</security:http>
<bean id="rememberMeServices"
class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
<property name="key" value="mustMatchRememberMeAuthenticationProvidersKey"/>
<property name="parameter" value="myParamName"/>
<!-- You must refer to a bean that implements UserDetailsService
in this example the bean id is userDetailsService -->
<property name="userDetailsService" ref="userDetailsService"/>
</bean>
As of Spring Security 3.2.x, you can set this with the remember-me-parameter parameter on the remember-me element.
According to the help file that comes with the Spring.NET framework, you can inject a dependancy defined in the local file by using an 'idref' tag along with a 'local' attribute.
I have been trying to do this with no success and was hoping someone had the experience to help me out.
Below I have a snippet from the config where I am passing it as a constructor argument, but I have tried setting it as a property as well. Both methods seem to yield the same error.
<object id="theTargetObject" type="TestClassLibrary.TargetObject, TestClassLibrary"/>
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<constructor-arg name="myClass">
<idref local="theTargetObject"/>
</constructor-arg>
</object>
Error creating context 'spring.root': Error creating object with name 'theClientObject' defined in 'file [C:\Test\TestApp\bin\Debug\my.config.xml]' : Unsatisfied dependency expressed through constructor argument with index 0 of type [TestClassLibrary.TargetObject] : Could not convert constructor argument value [theTargetObject] to required type [TestClassLibrary.TargetObject] : Cannot convert property value of type [System.String] to required type [TestClassLibrary.TargetObject] for property ''.
I guess gef was on the right way but accidentially mixed it up when pasting the snippet.You are looking for the <ref> element:
<object id="theTargetObject" type="TestClassLibrary.TargetObject, TestClassLibrary"/>
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<property name="myClass">
<ref local="theTargetObject"/>
</property>
the shorthand notation for this is:
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<property name="myClass ref="theTargetObject"/>
hth,
Erich
Please view the post http://forum.springsource.org/showthread.php?t=14211