Okay, turns out that the servlet 3.0 spec says that addMapping() doesn't override already-existing mappings. Resin puts in a default mapping for "/", and so I can't override it (they'll fix that in a future release). But something like "/*" works.
I'm now looking to see how to convert the following XML into annotations.
I can just create it, something like this:Code:<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="packagesToScan" value="com.foo.bar.model"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop> <prop key="hibernate.jdbc.batch_size">20</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.use_sql_comments">false</prop> <prop key="hibernate.generate_statistics">true</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" />
But as you can see in the code, I'm not sure how to wire it to the data source. Moreover, I don't know if I need to scan any packages, since I've already scanned my model package in the AppConfig.Code:@Configuration @ComponentScan(basePackages = { "com.foo.bar.model", "com.foo.bar.dao" }, excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Controller.class) }) public static class AppConfig { @Bean public org.springframework.jndi.JndiObjectFactoryBean dataSource() { org.springframework.jndi.JndiObjectFactoryBean bean = new org.springframework.jndi.JndiObjectFactoryBean(); bean.setJndiName("java:comp/env/jdbc/db"); return bean; } @Bean public org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean sessionFactory() { DataSource dataSource = <get a data source, but how? Can I @Autowire?>; org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean bean = new org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean(); bean.setDataSource(dataSource); return bean; } }
I guess the general question is, how do I create my beans in code and access created beans in the context.
You had suggested using org.springframework.web.servlet.config.annotation. WebMvcConfigurationSupport, but I'm trying to do this in my AppConfig, not my WebConfig, and I don't see an analogous class to inherit from for aid.
Thanks!


Reply With Quote