I want to create a project using smartfoxserver2x with spring framework and hibernate.
But I can't find how to use spring and hibernate in smartfoxserver2x.
Could someone help me?
I had put these code in the init method that I found on other website,but it still didn't work.
this is the code.
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);
and this is the exception
15:28:15,741 ERROR [main] managers.SFSExtensionManager - java.lang.NullPointerException: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Exception: java.lang.NullPointerException Message: * Null * Description: Extension initialization failed. +--- --- ---+ Stack Trace: +--- --- ---+ 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)
It seems the spring annotations did't work.So there is nullpoint exception because there is not object to be injected.
OK,this is my 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/>
I‘ve successfully used junit to test my codes, so I think it is because the smartfoxserver. But I can't find how to fix it.