av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

從Spring MVC XML文件移至javaconfig。我的數(shù)據(jù)庫(kù)XML文件真的讓我迷茫了

瀏覽:108日期:2024-04-18 14:42:29
如何解決從Spring MVC XML文件移至javaconfig。我的數(shù)據(jù)庫(kù)XML文件真的讓我迷茫了?

對(duì)于

<tx:annotation-driven transaction-manager='hibernateTransactionManager' />

注釋你的配置類,WebMVCConfig與

@EnableTransactionManagement

對(duì)于

<context:component-scan base-package='org.uftwf' />

將Package String添加到您的@ComponentScan字段basePackages

對(duì)于

<context:property-placeholder location='classpath:app.properties' />

用以下注釋您的Configuration類

@PropertySource(value = 'classpath:app.properties')

然后做你的PropertyPlaceholderConfigurer @Bean方法static。

對(duì)于

<jee:jndi-lookup jndi-name='java:jboss/datasources/MysqLDB' expected-type='javax.sql.DataSource' />

我想你可以做

@Beanpublic DataSource dataSource() throws Exception { Context ctx = new InitialContext(); return (DataSource) ctx.lookup('java:jboss/datasources/MysqLDB');}

無(wú)需自動(dòng)裝配會(huì)話工廠,只需調(diào)用您的@Bean方法

@Beanpublic HibernateTransactionManager transactionManager(){ HibernateTransactionManager htm = new HibernateTransactionManager(); htm.setSessionFactory(sessionFactory()); return htm;}解決方法

我從Spring MVC XML文件移動(dòng)到j(luò)avaconfig。我的數(shù)據(jù)庫(kù)XML文件真的讓我迷茫了。我不知道如何使Hibernate4工作以及我的JBossJNDI數(shù)據(jù)源工作。有人可以告訴我如何使javaconfig類像這種XML一樣工作。

這是我的database.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:tx='http://www.springframework.org/schema/tx' xmlns:jdbc='http://www.springframework.org/schema/jdbc' xmlns:jee='http://www.springframework.org/schema/jee' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd'> <context:property-placeholder location='classpath:app.properties' /> <context:component-scan base-package='org.uftwf' /> <tx:annotation-driven transaction-manager='hibernateTransactionManager' /> <jee:jndi-lookup jndi-name='java:jboss/datasources/mySQLDB'expected-type='javax.sql.DataSource' /> <bean class='org.springframework.orm.hibernate4.LocalSessionFactoryBean'><property name='dataSource' ref='dataSource' /><property name='annotatedClasses'> <list><value>org.uftwf.inquiry.model.MemberInquiryInformation</value> </list></property><property name='hibernateProperties'> <props><prop key='hibernate.dialect'>${hibernate.dialect}</prop><prop key='hibernate.show_sql'>${hibernate.show_sql}</prop><prop key='hibernate.use_sql_comments'>${hibernate.use_sql_comments}</prop><prop key='format_sql'>${format_sql}</prop> </props></property> </bean> <bean class='org.springframework.orm.hibernate4.HibernateTransactionManager'><property name='sessionFactory' ref='sessionFactory' /> </bean></beans>

這是我的javaconfig類:

@Configuration@EnableWebMvc@ComponentScan(basePackages= {'org.uftwf.inquiry'})@ImportResource('/WEB-INF/spring/root-config.xml')public class WebMVCConfig extends WebMvcConfigurerAdapter { private static final String MESSAGE_SOURCE = '/WEB-INF/classes/messages'; private static final Logger logger = LoggerFactory.getLogger(WebMVCConfig.class); @Value('${jdbc.driverClassName}') private String driverClassName; @Value('${jdbc.url}') private String url; @Value('${jdbc.username}') private String username; @Value('${jdbc.password}') private String password; @Value('${hibernate.dialect}') private String hibernateDialect; @Value('${hibernate.show_sql}') private String hibernateShowSql; @Value('${hibernate.hbm2ddl.auto}') private String hibernateHbm2ddlAuto; @Bean public PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer() {PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();ppc.setLocation(new ClassPathResource('application.properties'));ppc.setIgnoreUnresolvablePlaceholders(true);return ppc; } @Bean() public DataSource getDataSource() {DriverManagerDataSource ds = new DriverManagerDataSource();ds.setDriverClassName(driverClassName);ds.setUrl(url);ds.setUsername(username);ds.setPassword(password);return ds; } @Bean public LocalSessionFactoryBean sessionFactory() {LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();factoryBean.setDataSource(getDataSource());factoryBean.setHibernateProperties(getHibernateProperties());factoryBean.setPackagesToScan('org.uftwf.inquiry.model');return factoryBean; } @Bean public Properties getHibernateProperties() {Properties hibernateProperties = new Properties();hibernateProperties.setProperty('hibernate.dialect',hibernateDialect);//hibernateProperties.setProperty('hibernate.show_sql','true');//hibernateProperties.setProperty('hibernate.format_sql','true');hibernateProperties.setProperty('hibernate.hbm2ddl.auto','update');hibernateProperties.setProperty('javax.persistence.validation.mode','none');//Audit History flagshibernateProperties.setProperty('org.hibernate.envers.store_data_at_delete','true');hibernateProperties.setProperty('org.hibernate.envers.global_with_modified_flag','true');return hibernateProperties; } @Bean @Autowired public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {HibernateTransactionManager htm = new HibernateTransactionManager();htm.setSessionFactory(sessionFactory);return htm; } @Bean public ViewResolver resolver() {UrlBasedViewResolver url = new UrlBasedViewResolver();url.setPrefix('/WEB-INF/view/');url.setViewClass(JstlView.class);url.setSuffix('.jsp');return url; } @Bean(name = 'messageSource') public MessageSource configureMessageSource() {logger.debug('setting up message source');ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();messageSource.setBasename(MESSAGE_SOURCE);messageSource.setCacheSeconds(5);messageSource.setDefaultEncoding('UTF-8');return messageSource; } @Bean public LocaleResolver localeResolver() {SessionLocaleResolver lr = new SessionLocaleResolver();lr.setDefaultLocale(Locale.ENGLISH);return lr; } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) {logger.debug('setting up resource handlers');registry.addResourceHandler('/resources/').addResourceLocations('/resources/**'); } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {logger.debug('configureDefaultServletHandling');configurer.enable(); } @Override public void addInterceptors(final InterceptorRegistry registry) {registry.addInterceptor(new LocaleChangeInterceptor()); } @Bean public SimpleMappingExceptionResolver simpleMappingExceptionResolver() {SimpleMappingExceptionResolver b = new SimpleMappingExceptionResolver();Properties mappings = new Properties();mappings.put('org.springframework.web.servlet.PageNotFound','p404');mappings.put('org.springframework.dao.DataAccessException','dataAccessFailure');mappings.put('org.springframework.transaction.TransactionException','dataAccessFailure');b.setExceptionMappings(mappings);return b; } @Bean public RequestTrackerConfig requestTrackerConfig() {RequestTrackerConfig tr = new RequestTrackerConfig();tr.setPassword('Waiting#$');tr.setUrl('https://uftwfrt01-dev.uftmasterad.org/REST/1.0');tr.setUser('root');return tr; }}

我認(rèn)為我缺少的部分如下,但請(qǐng)多檢查我的課

<context:property-placeholder location='classpath:app.properties' /> <context:component-scan base-package='org.uftwf' /> <tx:annotation-driven transaction-manager='hibernateTransactionManager' /> <jee:jndi-lookup jndi-name='java:jboss/datasources/mySQLDB'expected-type='javax.sql.DataSource' />

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 亚洲情综合五月天 | 亚洲免费毛片 | 狠狠操狠狠操 | 男女免费观看在线爽爽爽视频 | 日韩精品免费 | 国外成人在线视频 | 天天综合成人网 | 福利网址 | 亚洲欧美激情国产综合久久久 | 国产午夜视频 | 成人久久久 | 精品一二区 | 在线观看中文字幕av | 欧美黄色录像 | 最新国产视频 | 亚洲精品久久久蜜桃网站 | 日韩av在线一区二区三区 | 激情欧美一区二区三区中文字幕 | 精品视频一区二区在线观看 | 久久精品亚洲一区二区三区浴池 | 色资源在线视频 | 91精品国产乱码久久久久久 | 国产在线高清 | 精品三级在线观看 | 亚洲一区二区中文字幕 | 一区二区高清 | 夜夜av| 亚洲人成人一区二区在线观看 | 欧美4p | 四虎永久免费黄色影片 | 日韩精品免费在线观看 | 欧美一级视频在线观看 | 亚洲在线一区二区 | 午夜免费成人 | 国产欧美精品一区二区 | 在线视频 亚洲 | av片在线免费看 | 青青草一区二区三区 | 精品欧美一区二区久久久伦 | 一级黄在线观看 | 久久高清免费视频 |