我想使用smartfoxserver2x和 spring 框架和休眠创建一个项目。
但是我在 smartfoxserver2x 中找不到如何使用 spring 和 hibernate。
有人可以帮助我吗?
我已经将这些代码放在我在其他网站上找到的 init 方法中,但它仍然不起作用。
这是代码。
ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
ClassLoader extensionLoader = getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(extensionLoader);
context = new GenericXmlApplicationContext(new ClassPathResource("/applicationContext.xml", extensionLoader));
Thread.currentThread().setContextClassLoader(origLoader);
这是例外
15:28:15,741 错误 [main] manager.SFSExtensionManager - java.lang.NullPointerException: :::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::: 异常:java.lang.NullPointerException 消息:* Null * 说明:扩展初始化失败。+--- --- ---+ 堆栈跟踪:+--- --- ---+ bingo_server.business.login.service.serviceImpl.VipServiceImpl.getVip(VipServiceImpl.java:21) bingo_server.extension.BingoExtension .init(BingoExtension.java:38) com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303) com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:425) com .smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:239) com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:292) com.smartfoxserver.v2.Main.main(Main.java:27 )
似乎弹簧注释不起作用。因此存在空点异常,因为没有要注入的对象。
好的,这是我的 applicationContext.xml
<!-- package-scan -->
<context:component-scan base-package="bingo_server">
</context:component-scan>
<!-- data-source -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver"></property>
<property name="jdbcUrl" value="jdbc:postgresql://127.0.0.1:5432/bingo"></property>
<property name="user" value="postgres"></property>
<property name="password" value="123"></property>
<property name="initialPoolSize" value="15"></property>
<property name="minPoolSize" value="1"></property>
<property name="maxPoolSize" value="50"></property>
<property name="acquireIncrement" value="5"></property>
<property name="maxStatements" value="100"></property>
<property name="maxIdleTime" value="200"></property>
<property name="checkoutTimeout" value="2000"></property>
</bean>
<!-- SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.PostgreSQL9Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.current_session_context_class">
org.springframework.orm.hibernate5.SpringSessionContext
</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>bingo_server.entity</value>
</list>
</property>
</bean>
<!-- transaction -->
<bean id="txManage" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManage">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" read-only="true" rollback-for="java.lang.Exception"></tx:method>
<tx:method name="insert*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="add*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="modify*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="change*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="delete*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="remove*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="del*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" isolation="REPEATABLE_READ"></tx:method>
<tx:method name="get*" propagation="NOT_SUPPORTED" read-only="true" rollback-for="java.lang.Exception"></tx:method>
<tx:method name="load*" propagation="NOT_SUPPORTED" read-only="true" rollback-for="java.lang.Exception"></tx:method>
<tx:method name="query*" propagation="NOT_SUPPORTED" read-only="true" rollback-for="java.lang.Exception"></tx:method>
<tx:method name="select*" propagation="NOT_SUPPORTED" read-only="true" rollback-for="java.lang.Exception"></tx:method>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="serviceMethods" expression="execution(* bingo_server.business.*.service.serviceImpl.*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"></aop:advisor>
</aop:config>
<!-- aop -->
<aop:aspectj-autoproxy/>
我已经成功使用junit来测试我的代码,所以我认为是因为smartfoxserver。但我找不到如何解决它。