小编Cha*_*ala的帖子

检查Maven版本

我刚刚安装了maven.我下载了分发,提取的文件并设置了bin值环境变量,但是当我输入mvn -version CMD时,我收到消息:

'mvn'不被识别为内部或外部命令,
可操作程序或批处理文件.

我正在写项目.我有一个项目DatabaseAPI,其中我有数据库逻辑和POJO类.第二个项目是CoreAPI,我有一些方法.对于DatabaseAPI,我使用eclipse(export - > jar)创建一个jar文件.在核心我添加了外部jar(DatabaseAPI.jar).对于CoreAPI,我使用eclipse(export - > jar)创建一个jar文件.在核心中我添加了外部jar(CoreAPI.jar),我尝试启动tomcat(我的项目中有servlet并且也可以使用).我在启动时遇到错误,错误是ClassNotFoundException(CoreAPI中的一个类没有找到).是使用Eclipse导出的问题吗?

java eclipse tomcat jar maven

33
推荐指数
3
解决办法
22万
查看次数

从servlet访问spring组件

我有一个控制器(例如.MyManager),我调用组件类(bean)的方法(例如myMethod()),例如MyComponent.我有servlet,我想调用myMethod().在servlet中,我通过@Autowired注释注释了MyManager ,尽管我得到了NullPointerException.我看到了这种话题,但它对我没用.为了想象,我写了一些代码:

public class myClass extends HttpServlet {

@Autowired
private MyComponent component;

public void init(ServletConfig config) throws ServletException{
super.init(config);
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}

protected void doGet(HttpServletRequest req,HttpServletResponse res) throws ... {

List<MyObject> objects =component.myMethod();  // Here is the problem, component is null

}

}

}
Run Code Online (Sandbox Code Playgroud)

我使用Spring配置文件"context.xml"并获得了bean(组件)对象,但是现在我在bean对象中注入了EntityManager有问题.现在它是null,任何人都可以帮我解决这个问题吗?还更新init()方法.

public void init(ServletConfig config) throws ServletException{
ApplicationContext con = new ClassPathXmlApplicationContext("context.xml");
component = (MyComponent) con.getBean("myBean");
}
Run Code Online (Sandbox Code Playgroud)

spring servlets spring-mvc autowired

0
推荐指数
1
解决办法
1263
查看次数

标签 统计

autowired ×1

eclipse ×1

jar ×1

java ×1

maven ×1

servlets ×1

spring ×1

spring-mvc ×1

tomcat ×1