我已经在线跟踪非常简单的示例在Spring中设置了一个cron作业但我每次都在我的Tomcat启动日志中不断收到此错误:
2015-05-25 00:32:58 DEBUG ScheduledAnnotationBeanPostProcessor:191 -
Could not find default TaskScheduler bean org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
2015-05-25 00:32:58 DEBUG ScheduledAnnotationBeanPostProcessor:202 - Could not
find default ScheduledExecutorService bean
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying
bean of type [org.springframework.scheduling.TaskScheduler] is defined
Run Code Online (Sandbox Code Playgroud)
并且用于实现cron的2个java类:
1)@Configuration类:
@Configuration
@EnableScheduling
public class ClearTokenStoreCronEnable {
final static Logger log =
LoggerFactory.getLogger(ClearTokenStoreCronEnable.class);
private @Autowired TokenStoreRepository tokenStoreRepository;
}
Run Code Online (Sandbox Code Playgroud)
和Cron工作班:
@Service
public class ClearTokenStoreWorkerService {
final static Logger log = LoggerFactory.getLogger(ClearTokenStoreWorkerService.class);
private @Autowired TokenStoreRepository tokenStoreRepository;
//@Scheduled(fixedDelay=5000)
//run …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的Spring Rest后端,它返回JSON数据.宁静的URL在我的浏览器中工作如下:
http://localhost:8080/abc/runlist
它返回如下数据:
[{"stock_num":"KOH19","damage":"Toronto (Oshawa)"},{"stock_num":"AZ235","damage":"Toronto (Oshawa)"},...
我有一个独立的html页面,不属于我的网络应用程序.我只想测试我的角度代码是否获取数据然后循环遍历它.
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in names">
{{ x }}
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:8080/abc/runlist")
.success(function (response) {$scope.names = response.records;});
});
</script>
yo yo
</body>
Run Code Online (Sandbox Code Playgroud)
`
为什么不起作用?我在Spring遇到了一些需要实现CORS的东西.我这样做了但仍然没有回复:
@Component
public class SimpleCORSFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse res, FilterChain
chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, …
Run Code Online (Sandbox Code Playgroud) 我想填充一个下拉列表,我不想继续访问数据库.我想在属性文件中包含我的国家/地区列表或语言列表.这样我就可以读取它,然后将其分配给变量.然后我可以通过ModelAndView类型返回它.
这是一个好方法吗?我不确定如何存储静态数据.我不想把它保留在一个类中,因为如果需要进行更改,更新它会更难.
我正在尝试将Spring-Security 4实现到我的Spring MVC web和rest app中.我添加了2个类来启用Spring安全性的java配置方式.我仍然希望保留我的web.xml而不是将整个项目更改为使用java配置.一旦我这样做,我收到以下错误:
29-May-2015 08:47:12.826 SEVERE [localhost-startStop-1]
org.apache.catalina.core.StandardContext.filterStart Exception starting
filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean
named 'springSecurityFilterChain' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
getBeanDefinition(DefaultListableBeanFactory.java:687)
Run Code Online (Sandbox Code Playgroud)
如您所见,它表示无法识别springSecurityFilterChain.这当然应该由@EnableWebSecurity启用,如下所示:
用于Spring Security的类:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("abc").password("123456").roles("USER");
auth.inMemoryAuthentication().withUser("admin").password("123456").roles("ADMIN");
auth.inMemoryAuthentication().withUser("dba").password("123456").roles("DBA");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/dba/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_DBA')")
.and().formLogin();
}
}
public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
//do nothing
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我将springSecurityFilterChain添加到我的web.xml,在运行时它会抱怨并说有一个重复的springSecurityFilterChain.我注意到最终在Java配置中,他们这样做:
public class MvcWebApplicationInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override …
Run Code Online (Sandbox Code Playgroud) spring-4 ×2
spring-mvc ×2
angularjs ×1
cron ×1
file ×1
get ×1
java ×1
javascript ×1
properties ×1