最近在开发多媒体问答系统,服务器端基本架构是mongodb+Spring+jerseyRest+Spring-data+java+maven3.0
客户端采用android+IOS两种方按。我负责服务器端和android端,本文将自己附上整个服务器配置过程中的BUG及其解决
《持续更新》
一,MAVEN控制下,将该工程分成几个子工程,其中mmqa工程主要负责系统的repostory层和service层,但是所有user都将放在user子工程中,因此user工程中也要有repostory和service的相应内容,在 对其进行添加时,使用Spring的@service进行依赖注入,运行后发生错误:
Error creating bean with name 'authRest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private nesdu.user.service.AccountService nesdu.mmqa.rest.AuthRest.accountService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private nesdu.user.repository.AccountRepository nesdu.user.service.AccountService.accountRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [nesdu.user.repository.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authRest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private nesdu.user.service.AccountService nesdu.mmqa.rest.AuthRest.accountService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private nesdu.user.repository.AccountRepository nesdu.user.service.AccountService.accountRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [nesdu.user.repository.AccountRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
也就是不能自动绑定,由于Spring控制整个工程,在检查service代码和web接口层代码没问题后,问题基本锁定在Spring的配置上:
添加 <mongo:repositories base-package="nesdu.user.repository" /> 让该子工程的代码可以访问数据库
二、最近出现Junit一直出错的问题,读异常发现是在ApplicationContext.xml上,原来关于上传的bean出错,导致不能正确绑定,删去部分代码,问题解决,删去的代码是:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件大小的参数 -->
<property name="maxUploadSize" value="1000000" />
</bean>
是用来上传视频用的,如果以后上传视频存在问题,就在拷贝回去……
三、android端的APP已经基本完成了,但是在测试时发现两个必须要解决的BUG
1 在某一页面注销用户时,若先删除用户信息,然后finish()该Activity,则会返回上一级Activity,但由于数据库中用户信息已经丢失,所以会跳错,解决办法在于如何更合理的推出APP,急救办法:单例模式:
(1)新建了用于保存所有Activity信息的单例工具:
import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
import android.app.Application;
public class ExitApplication extends Application {
private List<Activity> activityList=new LinkedList<Activity>();
private static ExitApplication instance;
private ExitApplication()
{
}
//单例模式中获取唯一的ExitApplication 实例
public static ExitApplication getInstance()
{
if(null == instance)
{
instance = new ExitApplication();
}
return instance;
}
//添加Activity 到容器中
public void addActivity(Activity activity)
{
activityList.add(activity);
}
//遍历所有Activity 并finish
public void exit()
{
for(Activity activity:activityList)
{
activity.finish();
}
System.exit(0);
}
}
(2)在所以已经打开的Activity的onCreate中添加:ExitApplication.getInstance().addActivity(this);
然后在需要退出程序的Button的OnClickListener中调用 ExitApplication.getInstance().exit(); 即完成全部的退出任务
2 某些机型上注册BUG(或者说只有一个机器没有BUG。。。)
解决办法:Catlog后发现是使用Spring for Android工具的错误,我在上传注册信息的时候采用的是PostForObject方法,有返回值,但返回值对于我来说没有用。。。
现改为postForLocation方法,没有返回值,有效.........