lunes, 12 de noviembre de 2007

Several applicationContext, split applicationContext

Para dividir el appCtx.xml en varios files:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext*.xml,/WEB-INF/security.xml
</param-value>
</context-param>

viernes, 9 de noviembre de 2007

Access the BeanFactory through ServletContext

Para acceder a la beanFactory dentro de alguna clase se registra el ContextListener en el web xml (generalmente ya está registrado para struts2):
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

En el código se accede a la factory:
WebApplicationContextUtils.getWebApplicationContext(servletContext);

jueves, 1 de noviembre de 2007

SQLServer express spring datasource config

    <bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=workflow;" />
<property name="username" value="root" />
<property name="password" value="xxxx" />
</bean>

<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">none</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
</bean>

miércoles, 24 de octubre de 2007

null Bean

Testeando con JUnit4 después de inicializar un bean a través de spring y asignarlo a un field en el @BeforeClass cuando intento acceder a este bean en el test me encuentro con un null pointer. No se como se manejarán los scopes en JUnit o si es natural de Spring:

SpringWorkflowTest test = new SpringWorkflowTest();
MyWorkflow workflow = (MyWorkflow) beanFactory.getBean("workflow");
test.setWorkflow(workflow);

La beanFactory es un global field.
Creo que el problema pasa porque la instancia que se testea debe ser una nueva y no la que tiene asignado el workflow. Cambié el getBean adentro del test para que funcione.

jueves, 13 de septiembre de 2007

Struts2 action wiring (not wired)

En el appctx el wiring del bean cableando la property quedaba en null

bean name="countryAction"
class="edu.matias.region.web.struts.actions.CountryAction"
property name="manager" ref="countryManager" /
/bean

sin embargo por constructor (creando el constructor en el action) enlazo:

bean id="countryAction" scope="prototype"
class="edu.matias.region.web.struts.actions.CountryAction"
constructor-arg ref="countryManager" /
/bean



Bean xml annotation change STR1>STR2

En vez del campo name, los bean en el appctx se identifican con el campo id.

viernes, 31 de agosto de 2007

'sessionFactory' or 'hibernateTemplate' is required

Spring boot:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'personDao' while setting bean property 'dao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

Solución: definir en el xml el bean "sessionFactory" para que se cablee a los beans que lo necesitan

Generic Dao Constructor needed

BeanCreationException: Error creating bean with name 'personService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'personDao' while setting bean property 'dao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com....PersonDaoHibernate]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com....PersonDaoHibernate.()

martes, 21 de agosto de 2007

Exceptions

Como capturar exceptions de JPA?
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
disparada.

martes, 7 de agosto de 2007

JPA init

DEBUG - Creating shared instance of singleton bean 'transactionManager'
DEBUG - Creating instance of bean 'transactionManager' with merged definition [Root bean: class [org.springframework.orm.jpa.JpaTransactionManager]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyException in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [D:\work\loader\applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [D:\work\loader\applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dataSource' of bean class [org.springframework.orm.jpa.LocalEntityManagerFactoryBean]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Alternativa
Cambio de clases en el xml: sale LocalEntityManagerFactoryBean y entra LocalContainerEntityManagerFactoryBean

Wiring

Sin wiring JPA usando
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"applicationContext.xml"));

cambiado a
ApplicationContext factory= new FileSystemXmlApplicationContext(
"applicationContext.xml");