注入自动连接的依赖项在春天失败了

时间:2017-09-10 03:54:14

标签: java spring hibernate spring-mvc

我是Spring的新手并且正在开发一个应用程序。我在catalina中收到错误日志,如下所示。我已经通过服务自动控制我的控制器,并使用dao服务。

异常的原因是什么?----------------------

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.typeset.blog.services.BlogService com.typeset.blog.controllers.MainController.blogService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.typeset.blog.dao.BlogDao com.typeset.blog.services.BlogService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao' defined in file [C:\Users\Rumela\Downloads\blog-engine\blog-with-in-place-comments-master\blog\target\blog-with-comments\WEB-INF\classes\com\typeset\blog\dao\BlogDao.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0': Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'ehcache' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 58 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.typeset.blog.dao.BlogDao com.typeset.blog.services.BlogService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao' defined in file [C:\Users\Rumela\Downloads\blog-engine\blog-with-in-place-comments-master\blog\target\blog-with-comments\WEB-INF\classes\com\typeset\blog\dao\BlogDao.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0': Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'ehcache' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ... 60 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.typeset.blog.dao.BlogDao com.typeset.blog.services.BlogService.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao' defined in file [C:\Users\Rumela\Downloads\blog-engine\blog-with-in-place-comments-master\blog\target\blog-with-comments\WEB-INF\classes\com\typeset\blog\dao\BlogDao.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0': Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'ehcache' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 71 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogDao' defined in file [C:\Users\Rumela\Downloads\blog-engine\blog-with-in-place-comments-master\blog\target\blog-with-comments\WEB-INF\classes\com\typeset\blog\dao\BlogDao.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0': Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'ehcache' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ... 73 more
Caused by: org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0': Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'ehcache' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:218)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:109)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:447)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:333)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1571)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    ... 82 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0': Cannot resolve reference to bean 'cacheManager' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'ehcache' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor.getAdvice(AbstractBeanFactoryPointcutAdvisor.java:88)
    at org.springframework.aop.framework.CglibAopProxy$ProxyCallbackFilter.hashCode(CglibAopProxy.java:939)
    at org.springframework.cglib.proxy.Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$4ce19e8f.hashCode(<generated>)
    at org.springframework.cglib.core.DefaultNamingPolicy.getClassName(DefaultNamingPolicy.java:39)
    at org.springframework.cglib.core.AbstractClassGenerator.getClassName(AbstractClassGenerator.java:72)
    at org.springframework.cglib.core.AbstractClassGenerator.getClassName(AbstractClassGenerator.java:66)
    at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:474)
    at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
    at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
    at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)
    at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:202)
    ... 89 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Cannot resolve reference to bean 'ehcache' while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 112 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 122 more
Caused by: net.sf.ehcache.CacheException: java.io.IOException: Access is denied
    at net.sf.ehcache.DiskStorePathManager$DiskStorePath.<init>(DiskStorePathManager.java:331)
    at net.sf.ehcache.DiskStorePathManager.resolveAndLockIfNeeded(DiskStorePathManager.java:145)
    at net.sf.ehcache.DiskStorePathManager.getFile(DiskStorePathManager.java:262)
    at net.sf.ehcache.DiskStorePathManager.getFile(DiskStorePathManager.java:251)
    at net.sf.ehcache.store.disk.DiskStorageFactory.<init>(DiskStorageFactory.java:127)
    at net.sf.ehcache.store.disk.DiskStore.create(DiskStore.java:154)
    at net.sf.ehcache.store.disk.DiskStore.createCacheStore(DiskStore.java:182)
    at net.sf.ehcache.Cache.initialise(Cache.java:1216)
    at net.sf.ehcache.CacheManager.initializeEhcache(CacheManager.java:1357)
    at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1423)
    at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:819)
    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:498)
    at net.sf.ehcache.CacheManager.init(CacheManager.java:394)
    at net.sf.ehcache.CacheManager.<init>(CacheManager.java:269)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1103)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1079)
    at net.sf.ehcache.CacheManager.create(CacheManager.java:1062)
    at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:144)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
    ... 129 more
Caused by: java.io.IOException: Access is denied
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:1012)
    at net.sf.ehcache.DiskStorePathManager$DiskStorePath.<init>(DiskStorePathManager.java:322)
    ... 148 more

我的调度程序servelet.xml看起来像

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd 
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-4.1.xsd
http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task-4.1.xsd
http://www.springframework.org/schema/cache 
http://www.springframework.org/schema/cache/spring-cache-4.1.xsd">

    <context:component-scan base-package="com.typeset.blog" />
    <cache:annotation-driven />

    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="ehcache" />
    </bean>
    <bean id="ehcache"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:ehcache.xml" />
        <property name="shared" value="true" />
    </bean>

    <context:annotation-config />
    <task:annotation-driven />
    <mvc:annotation-driven />

    <context:property-placeholder location="classpath*:app.properties" />
    <bean id="springDataSource" class="org.apache.commons.dbcp2.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/blogWithComments" />
        <property name="username" value="***" />
        <property name="password" value="***" />
        <property name="initialSize" value="20" />
        <property name="maxTotal" value="30" />
    </bean>
</beans>

我的dao类看起来像这样:

    @Component
public class BlogDao {

    @Autowired
    private DataSource dataSource;

    private JdbcTemplate jdbcTemplate;

    private static final Logger logger = LoggerFactory.getLogger(BlogDao.class);

    @PostConstruct
    public void init(){
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public String addBlog(Blog blog){

        String id=Long.toString((long)(Math.abs(UUID.randomUUID().getLeastSignificantBits()/Math.pow(10,11))));
        blog.setId(id);
        Object[] params = new Object[] {id, blog.getTitle(), blog.getPlainText()};      
        int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR};
        int rowsUpdated=jdbcTemplate.update(Constants.ADD_BLOG, params, types);
        DetailedBlog detailedBlog=new DetailedBlog(id, blog.getTitle(), blog.getPlainText());
        int i=0, rowsUpdatedP=0;
        for(Paragraph p:detailedBlog.getParagraphs()){
            params = new Object[] {id, p.getParagraphId(),p.getParagraph()};        
            types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR};
            rowsUpdatedP=jdbcTemplate.update(Constants.ADD_BLOG_PARAGRAPHS, params, types);
            i++;
        }
        if(rowsUpdated==1 && rowsUpdatedP==detailedBlog.getParagraphs().length){
            return Constants.SUCCESS_MESSAGE;
        }
        else
            return Constants.ERROR_MESSAGE;
    }
    @Cacheable("blog_cache")
    public Blog[] getAllBlogs() {
        List<Map<String, Object>> list=jdbcTemplate.queryForList(Constants.GET_ALL_BLOGS);
        Class blogClass=Blog.class;
        Method[] methods = blogClass.getMethods();
        Map<String, Method> map=new HashMap<String, Method>();
        String name="";
        Blog[] blogs=new Blog[list.size()];
        for(Method m:methods){
            name=m.getName();

            //extract all setters
            if(name.contains("set"))
                map.put(name.substring(name.indexOf("set")+3).toLowerCase(), m);
        }
        logger.info("all setters: {}",map);
        int i=0;
        Blog blog=null;
        for(Map<String, Object> row: list){
            logger.info("Row: {}",row);
            blog=new Blog();
            for(String value: row.keySet()){
                try {
                    //populate the pojo
                    if(map.get(value.toLowerCase())!=null)
                        map.get(value.toLowerCase()).invoke(blog, row.get(value));                  
                } catch (Exception e) {
                    logger.error("Error",e);
                }
            }
            logger.info(""+blog);
            blogs[i]=blog;
            i++;
        }
        return blogs;
    }

    public DetailedBlog getDetailedBlog(String id) {
        DetailedBlog detailedBlog=new DetailedBlog();
        detailedBlog.setId(id);
        Map<String, Object> blog=jdbcTemplate.queryForMap(Constants.SELECT_BLOG+id+"'");
        List<Map<String, Object>> paragraphs=jdbcTemplate.queryForList(Constants.SELECT_PARAGRAPHS+id+"'");
        List<Map<String, Object>> comments=jdbcTemplate.queryForList(Constants.SELECT_COMMENTS+id+"'");
        detailedBlog.setTitle((String)blog.get("title"));
        detailedBlog.setPlainText((String)blog.get("plainText"));
        Paragraph para=null;
        List<Paragraph> list=new ArrayList<Paragraph>();
        Map<String,Paragraph> map = new HashMap<String, Paragraph>();
        logger.debug(comments.size()+" "+paragraphs.size());
        if(paragraphs.size()>0){
            for(Map<String, Object> paragraph: paragraphs){
                para=new Paragraph();
                para.setParagraphId((String)paragraph.get("paragraphId"));
                para.setParagraph((String)paragraph.get("paragraph"));
                map.put(para.getParagraphId(), para);
            }
            logger.debug("map "+map.toString());
            for(Map<String, Object> comment: comments){
                para=map.get(comment.get("paragraphId"));
                logger.debug("paragraph "+para.toString());
                List<String> comm=para.getComments();
                if(comm==null){
                    comm=new ArrayList<String>();
                    para.setComments(comm);
                }
                comm.add((String)comment.get("comment"));                           
                logger.debug("comment "+comm.toString());
            }
        }
        logger.debug(map.toString());

        detailedBlog.setParagraphs(map.values().toArray(new Paragraph[0]));
        return detailedBlog;
    }

    public String addComment(String blogId, String paraId, String comment) {
        String id=Long.toString((long)(Math.abs(UUID.randomUUID().getLeastSignificantBits()/Math.pow(10,11))));
        Object[] params = new Object[] {blogId, paraId, id, comment};       
        int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,Types.VARCHAR};
        int rowsUpdated=0;
        try{
            rowsUpdated=jdbcTemplate.update(Constants.ADD_COMMENT, params, types);
        }catch(Exception e){
            logger.error("error",e);
        }
        if(rowsUpdated==1){
            return Constants.SUCCESS_MESSAGE;
        }
        else
            return Constants.ERROR_MESSAGE;

    }
}

有人可以帮帮我吗?enter code here

2 个答案:

答案 0 :(得分:0)

at java.io.File.createNewFile(File.java:1012) 

抛出Exception因为创建新文件的方法应该具有足够的权限来创建/编辑文件,实际上,您会收到错误消息,告诉您没有权限。

您需要更改要在其中创建文件的目录的访问控制列表(ACL)

答案 1 :(得分:0)

我会检查ehcache.xml,可能你有类似的东西

<diskStore path="/auto/default/path"/>

看起来那里指定的路径不正确,或者您的用户没有权限在那里写文件。