Java properties:放置由“引用”引用的文件的位置;类路径:ds/datasource cfg.properties“;
所以我试着在这里运行一个示例 根据这篇文章,Eclipse的位置如下: 所以我也在Netbeans中做了: 但它给了我错误:Java properties:放置由“引用”引用的文件的位置;类路径:ds/datasource cfg.properties“;,java,spring,netbeans,Java,Spring,Netbeans,所以我试着在这里运行一个示例 根据这篇文章,Eclipse的位置如下: 所以我也在Netbeans中做了: 但它给了我错误: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: org.o7planning.springmvcjdbc.config.ApplicationContextConfig; nested exception is java.io
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: org.o7planning.springmvcjdbc.config.ApplicationContextConfig;
nested exception is java.io.FileNotFoundException: class path resource [ds/datasource-cfg.properties] cannot be opened because it does not exist
及
我一直在读一些关于netbeans中的.properties
资源访问的帖子,但似乎什么都不管用。错误只来自于那些(访问部件)。代码总体上还不错
下面的类中声明了“类路径:ds/datasource cfg.properties”<代码>ApplicationContextConfig.java
package org.o7planning.springmvcjdbc.config;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@ComponentScan("org.o7planning.springmvcjdbc.*")
@EnableTransactionManagement
// HERE ..!!!
// Load to Environment.
@PropertySources({ @PropertySource("classpath:ds/datasource-cfg.properties") })
public class ApplicationContextConfig {
// The Environment class serves as the property holder
// and stores all the properties loaded by the @PropertySource
@Autowired
private Environment env;
@Bean(name = "viewResolver")
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/pages/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Bean(name = "dataSource")
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
// See: datasouce-cfg.properties
dataSource.setDriverClassName(env.getProperty("ds.database-driver"));
dataSource.setUrl(env.getProperty("ds.url"));
dataSource.setUsername(env.getProperty("ds.username"));
dataSource.setPassword(env.getProperty("ds.password"));
System.out.println("## getDataSource: " + dataSource);
return dataSource;
}
@Bean(name = "transactionManager")
public DataSourceTransactionManager getTransactionManager() {
DataSourceTransactionManager txManager = new DataSourceTransactionManager();
DataSource dataSource = this.getDataSource();
txManager.setDataSource(dataSource);
return txManager;
}
}
那么把这个资源文件夹放在netbeans的哪里呢?好的,我找到了:
我谨此评论:
//@PropertySources({ @PropertySource("classpath:ds/datasource-cfg.properties") })
然后我加上这个
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
在扩展webmvcconfiguerradapter
的类中,在dsHi@Jens之前添加一个斜杠,同样的错误,为什么在netbeans中访问东西如此困难
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}