小编Evg*_*rov的帖子

Angular 2使用另一个模块中的组件

我有使用angular-cli生成的Angular 2(版本2.0.0 - 最终版)app.

当我创建一个组件并将其添加到AppModule声明数组时,它一切都很好,它可以工作.

我决定将组件分开,所以我创建了TaskModule一个组件TaskCard.现在我想用TaskCard在的组成部分之一AppModule(的Board成分).

的AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { BoardComponent } from './board/board.component';
import { LoginComponent } from './login/login.component';

import { MdButtonModule } from '@angular2-material/button';
import { MdInputModule } from '@angular2-material/input';
import { MdToolbarModule } from '@angular2-material/toolbar';

import …
Run Code Online (Sandbox Code Playgroud)

typescript angular-module angular

171
推荐指数
3
解决办法
14万
查看次数

SpringMVC RequestMapping用于GET参数

如何让RequestMapping处理url中的GET参数?例如,我有这个网址

http://localhost:8080/userGrid?_search=false&nd=1351972571018&rows=10&page=1&sidx=id&sord=desc
Run Code Online (Sandbox Code Playgroud)

(来自jqGrid)

我的RequestMapping应该怎么样?我想使用HttpReqest获取参数

试过这个:

@RequestMapping("/userGrid")
    public @ResponseBody GridModel getUsersForGrid(HttpServletRequest request)
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

java spring spring-mvc

64
推荐指数
4
解决办法
19万
查看次数

Spring Boot如何运行批处理作业

我按照这个样本进行Spring Batch with Boot.

运行main方法时,将执行作业.这样我就无法弄清楚如何控制作业执行.例如,您如何安排作业,或访问作业执行或设置作业参数.

我试着注册我自己的JobLauncher

@Bean
public JobLauncher jobLauncher(JobRepository jobRepo){
    SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
    simpleJobLauncher.setJobRepository(jobRepo);
    return simpleJobLauncher;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在main方法中使用它时:

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);    
    JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);
    //try catch removed for readability
    jobLauncher.run(ctx.getBean(Job.class), new JobParameters());   
}
Run Code Online (Sandbox Code Playgroud)

加载上下文后再次执行作业,JobInstanceAlreadyCompleteException当我尝试手动运行时,我得到了该作业.有没有办法阻止自动执行作业?

java spring spring-batch spring-boot

41
推荐指数
1
解决办法
3万
查看次数

Spring Security自定义身份验证 - AuthenticationProvider与UserDetailsS​​ervice

据我所知,当你想在Spring Security中进行自定义身份验证时,你可以实现自定义AuthenticationProvider或自定义UserDetailsService.

@Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth    
            //.authenticationProvider(authProvider)  // option 1
            .userDetailsService(userDetailsService); // option 2

    }
Run Code Online (Sandbox Code Playgroud)

在AuthenticationProvider中,您可以检查用户名和密码,并返回Authentication其中的自定义对象.

public Authentication authenticate(Authentication authentication){
        if (checkUsernameAndPassword(authentication)) {
            CustomUserDetails userDetails = new CustomUserDetails();
            //add whatever you want to the custom user details object
            return new UsernamePasswordAuthenticationToken(userDetails, password, grantedAuths);
        } else {
            throw new BadCredentialsException("Unable to auth against third party systems");
        }
    }
Run Code Online (Sandbox Code Playgroud)

UserDetailsService您只获取用户名时,当您返回自定义UserDeatails时,框架会检查密码.

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        CustomUserDetails user …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security

34
推荐指数
3
解决办法
1万
查看次数

获取EntityManagerFactory的最佳实践

在Web应用程序(jsp/servlets)中获取EntityManagerFactory的最佳方法是什么?这是一个好方法何时应该创建/打开EntityManagerFactory实例?或者从JNDI或其他东西获得它更好吗?

java jpa jndi

23
推荐指数
1
解决办法
4万
查看次数

我应该如何以及何时从数据库中为h:dataTable加载模型

我有一个数据表如下:

<h:dataTable value="#{bean.items}" var="item">
Run Code Online (Sandbox Code Playgroud)

我想用从服务方法获得的数据库中的集合填充它,以便在初始(GET)请求期间打开页面时立即显示它.我什么时候应该打电话给服务方法?为什么?

  1. 在加载页面之前调用它.但是怎么样?
  2. 在页面加载期间调用它.怎么样?
  3. 在getter方法中调用它.但它被多次调用.
  4. 别的什么?

datatable getter jsf loading

13
推荐指数
1
解决办法
8062
查看次数

Eclipse不会自动将servlet添加到web.xml中?

我以前使用Eclipse Galileo,但现在我有Helios.Galileo曾经自动添加我的servlet web.xml,但是在Helios我自己必须这样做.

我可以配置一些东西让它再次自动化吗?

eclipse automation servlets

11
推荐指数
2
解决办法
4万
查看次数

在托管bean构造函数中访问注入的依赖项会导致NullPointerException

我正在尝试将DAO注入托管属性.

public class UserInfoBean {

    private User user;

    @ManagedProperty("#{userDAO}")
    private UserDAO dao;

    public UserInfoBean() {
        this.user = dao.getUserByEmail("test@gmail.com");
    }

    // Getters and setters.
}
Run Code Online (Sandbox Code Playgroud)

在创建bean之后注入DAO对象,但它null在构造函数中并因此导致NullPointerException.如何使用注入的托管属性初始化托管bean?

jsf constructor nullpointerexception managed-bean managed-property

11
推荐指数
1
解决办法
3603
查看次数

如何使用Spring MVC处理未知数量的参数

我想使用JQuery的Sortable(http://jqueryui.com/sortable/#connect-lists),所以我的左边列表将以这样的结尾

<ul>
    <li>
        Some txt1 
        <input type="hidden" name="li1" value="1"/>
    </li>
    <li>
        Some txt2 
        <input type="hidden" name="li2" value="2"/>
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

<li>每次的数量都不同.我的想法是将所有隐藏的输入值和名称放在数组中并将数组作为JSON数据发布,但我的Controller应该如何?有没有办法"等待"控制器中的某些内容列表.例如:

@RequestMapping(value = "/listItems")
    public @ResponseBody GridModel getUsersForGrid(@RequestParam(value = "items") List<NameIdPair> items){...}
Run Code Online (Sandbox Code Playgroud)

javascript java jquery spring spring-mvc

11
推荐指数
1
解决办法
4563
查看次数

Websockets和负载平衡

Spring和Java EE对websockets提供了很好的支持.例如在Spring中,您可以:

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new MyHandler(), "/myHandler")
            .addInterceptors(new HttpSessionHandshakeInterceptor());
    }

}
Run Code Online (Sandbox Code Playgroud)

通过MyHandler类,您可以发送和侦听HTML5 websocket的消息.

var webSocket = 
      new WebSocket('ws://localhost:8080/myHandler');
 webSocket.onmessage = function(event) {
      onMessage(event)
    };
Run Code Online (Sandbox Code Playgroud)

问题是如果您在负载均衡器后面运行多个服务器.服务器A的客户端不会收到服务器B上的事件通知.

Spring中使用带有Stomp协议的消息代理解决了这个问题(http://assets.spring.io/wp/WebSocketBlogPost.html)

由于使用处理程序和"本机"html5 websockets对我来说更容易,然后是Stomp方式,我的问题是:

  1. 没有Stomp协议使用消息代理是否可行?
  2. 还有其他选择可以克服负载平衡问题吗?

javascript java html5 spring websocket

9
推荐指数
1
解决办法
2569
查看次数