WebApplicationInitializer提供了一种以编程方式表示标准web.xml文件的一部分的方法 - servlet,过滤器,监听器.
但是,我无法找到使用WebApplicationInitializer表示这些元素(会话超时,错误页面)的好方法,是否仍需要维护这些元素的web.xml?
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/uncaughtException</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/resourceNotFound</location>
</error-page>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spring AOP和Spring MVC Controller.我有3个方面,并希望按特定顺序.为了做到这一点,我使用Ordered接口并实现getOrder方法:
@Aspect
@Component
public class LoggingAspect implements Ordered{
public int getOrder() {
System.out.println("Abra");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
建议课程:
@Component
@Controller
public class HomeController {
Run Code Online (Sandbox Code Playgroud)
切入点:
@Aspect
public class SystemArchitecture {
@Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))")
public void inHomeController(){}
@Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))")
public void loggable(){}
@Pointcut("execution (* com.jajah.StorageManager.HomeController.*(..))")
public void authenticated(){}
}
Run Code Online (Sandbox Code Playgroud)
组态:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<annotation-driven />
<context:annotation-config />
<aop:aspectj-autoproxy proxy-target-class="false"/>
<beans:bean id="AuthenticationAspect" class="com.jajah.CommonAspects.SecurityAspects.OAuthAspect"/>
<beans:bean id="ErrorHandlingAspect" …Run Code Online (Sandbox Code Playgroud) 我已经声明了以下方面建议dao调用,我正在尝试运行@Before建议,但它不起作用.
这就是方面.
package com.hedgebenefits.aop;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class AccessControlAspect {
@Before("within(com.hedgebenefits.daos..*) && execution(public * *(..))")
public void daoCall() {
System.out.println("Before advice invoked for DAO method called ");
}
}
Run Code Online (Sandbox Code Playgroud)
我的application-context.xml具有以下标记
<aop:aspectj-autoproxy/>
Run Code Online (Sandbox Code Playgroud)
我的Dao课程如下:
package com.hedgebenefits.daos.impl;
import com.hedgebenefits.daos.AdminDao;
import com.hedgebenefits.domain.Admin;
import org.springframework.stereotype.Repository;
@Repository
public class AdminDaoImpl implements AdminDao{
@Override
public void save(Admin admin) {
}
}
Run Code Online (Sandbox Code Playgroud)
我放了一个断点,但我可以看到它不活跃,我肯定在这里做了一些愚蠢的错误,但无法搞清楚.PL.咨询.
我安装了Spring Tool Suite,现在将它用于一个小样本项目.但是我的dispatcher-servlet.xml文件中出现错误:
Build path is incomplete. Cannot find class file for org/springframework/beans/factory/Aware
Run Code Online (Sandbox Code Playgroud)
此处突出显示此错误:
<bean
**class="org.springframework.web.servlet.view.InternalResourceViewResolver">**
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
任何想法?
这可能是一个基本的scala问题,但无法弄清楚如何:
如何使用Scala表达此java循环:
for (int i=1;i<100000;i=2*i)
Run Code Online (Sandbox Code Playgroud)
我理解这是一种可能的方式:
def loopByTwiceBefore(from:Int, to:Int)(f:Int=>Unit):Unit = {
if (from<to){
f(from)
loopByTwiceBefore(from*2, to)(f);
}
}
Run Code Online (Sandbox Code Playgroud)
但是在Scala中是否有更规范的方法可以做到这一点.
我想使用MongoRepository接口,但我有一个BeanCreationException异常.ComponentScan和MappingBasePackage字符串已正确填充.
这是我的代码:
(Jersey类)@Component @Path("技能")公共类SkillREST {
@Autowired
private UserService userService;
@POST
@Path("/{token}")
@Produces({MediaType.APPLICATION_JSON})
public List<Skill> addSkill(@PathParam("token") String token, Skill skill){
return userService.getAllSkills();
}
}
Run Code Online (Sandbox Code Playgroud)
以下是未正确自动装配存储库的服务:
@Component
public class UserService {
@Autowired
SkillRepository skillRepository;
public List<Skill> getAllSkills(){
return skillRepository.findAll();
}
}
@Repository
public interface SkillRepository extends MongoRepository<Skill, String> {
}
Run Code Online (Sandbox Code Playgroud)
Spring配置类:
@Configuration
@PropertySource("classpath:mongodb.properties")
@EnableMongoRepositories
@ComponentScan("com.headlezz")
public class SpringMongoConfig extends AbstractMongoConfiguration {
@Inject
Environment environment;
@Override
public String getDatabaseName() {
return environment.getProperty("db.name");
}
@Override
@Bean
public Mongo mongo() throws Exception {
return new …Run Code Online (Sandbox Code Playgroud)